--01
CREATE OR REPLACE PUBLIC SYNONYM  DV_PL_REFSQLS                  FOR SYS.DV_PL_REFSQLS 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_REPL_STATUS                 FOR SYS.DV_REPL_STATUS 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_GMA_STATS                     FOR SYS.DV_GMA_STATS 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_LIBRARY_CACHE                FOR SYS.DV_LIBRARY_CACHE 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_UNDO_SEGMENTS                FOR SYS.DV_UNDO_SEGMENTS 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_TEMP_UNDO_SEGMENT           FOR SYS.DV_TEMP_UNDO_SEGMENT 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_UNDO_STATS                  FOR SYS.DV_UNDO_STATS
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_INDEX_COALESCE              FOR SYS.DV_INDEX_COALESCE
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_INDEX_RECYCLE              FOR SYS.DV_INDEX_RECYCLE
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_INDEX_REBUILD              FOR SYS.DV_INDEX_REBUILD
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_SQL_POOL                    FOR SYS.DV_SQL_POOL
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_OPEN_CURSORS                 FOR SYS.DV_OPEN_CURSORS 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_DC_POOLS                     FOR SYS.DV_DC_POOLS 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_PL_MANAGER                  FOR SYS.DV_PL_MANAGER 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_FREE_SPACE                  FOR SYS.DV_FREE_SPACE
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_HA_SYNC_INFO                FOR SYS.DV_HA_SYNC_INFO
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_HBA                         FOR SYS.DV_HBA
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_INSTANCE                    FOR SYS.DV_INSTANCE
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_RUNNING_JOBS                FOR SYS.DV_RUNNING_JOBS
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_LOG_FILES                     FOR SYS.DV_LOG_FILES 
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_SESSIONS                     FOR SYS.DV_SESSIONS 
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_BUFFER_POOLS                 FOR SYS.DV_BUFFER_POOLS 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_PARAMETERS                   FOR SYS.DV_PARAMETERS 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_USER_PARAMETERS              FOR SYS.DV_USER_PARAMETERS
/
GRANT SELECT ON DV_USER_PARAMETERS TO PUBLIC
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_TEMP_POOLS                   FOR SYS.DV_TEMP_POOLS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_OBJECT_CACHE             FOR DV_OBJECT_CACHE 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_LOCKS                        FOR SYS.DV_LOCKS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_ARCHIVED_LOGS                FOR SYS.DV_ARCHIVED_LOGS
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_ARCHIVE_GAPS                 FOR SYS.DV_ARCHIVE_GAPS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_ARCHIVE_THREADS           FOR SYS.DV_ARCHIVE_THREADS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_ARCHIVE_DEST_STATUS         FOR SYS.DV_ARCHIVE_DEST_STATUS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_DATABASE                    FOR SYS.DV_DATABASE 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_GMA                         FOR SYS.DV_GMA 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_LOCKED_OBJECTS               FOR SYS.DV_LOCKED_OBJECTS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_STANDBYS             FOR SYS.DV_STANDBYS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_TABLESPACES                  FOR SYS.DV_TABLESPACES 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_SPINLOCKS                    FOR SYS.DV_SPINLOCKS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_SQLS                     FOR SYS.DV_SQLS 
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_ANONYMOUS                    FOR SYS.DV_ANONYMOUS 
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_PL_ENTITY                    FOR SYS.DV_PL_ENTITY 
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_SESSION_WAITS                FOR SYS.DV_SESSION_WAITS 
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_SESSION_EVENTS               FOR SYS.DV_SESSION_EVENTS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_SYS_EVENTS                FOR SYS.DV_SYS_EVENTS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_ME                          FOR SYS.DV_ME 
/                                                               
GRANT SELECT ON DV_ME TO PUBLIC                                  
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_DATA_FILES                    FOR SYS.DV_DATA_FILES 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_SYS_STATS                     FOR SYS.DV_SYS_STATS 
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_MEM_STATS                     FOR SYS.DV_MEM_STATS 
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_SYSTEM                      FOR SYS.DV_SYSTEM 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_VERSION                     FOR SYS.DV_VERSION
/
GRANT SELECT ON   DV_VERSION to PUBLIC
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_CTRL_VERSION                     FOR SYS.DV_CTRL_VERSION
/
GRANT SELECT ON   DV_CTRL_VERSION to PUBLIC
/                                                             
CREATE OR REPLACE PUBLIC SYNONYM  DV_TRANSACTIONS                 FOR SYS.DV_TRANSACTIONS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_ALL_TRANS                   FOR SYS.DV_ALL_TRANS
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_GLOBAL_TRANSACTIONS         FOR SYS.DV_GLOBAL_TRANSACTIONS
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_RESOURCE_MAP                FOR SYS.DV_RESOURCE_MAP 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_USER_ASTATUS_MAP            FOR SYS.DV_USER_ASTATUS_MAP
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_DYNAMIC_VIEWS                FOR SYS.DV_DYNAMIC_VIEWS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_DYNAMIC_VIEW_COLS         FOR SYS.DV_DYNAMIC_VIEW_COLS 
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_BACKUP_PROCESSES              FOR SYS.DV_BACKUP_PROCESSES
/                                                               
                                                                
CREATE OR REPLACE PUBLIC SYNONYM  DV_USER_ADVISORY_LOCKS         FOR SYS.DV_USER_ADVISORY_LOCKS
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_CONTROL_FILES                 FOR SYS.DV_CONTROL_FILES
/                                                               
CREATE OR REPLACE PUBLIC SYNONYM  DV_REACTOR_POOLS                FOR SYS.DV_REACTOR_POOLS
/
CREATE OR REPLACE PUBLIC SYNONYM  NLS_SESSION_PARAMETERS        FOR SYS.NLS_SESSION_PARAMETERS
/
GRANT SELECT ON NLS_SESSION_PARAMETERS TO PUBLIC
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_SEGMENT_STATS          FOR SYS.DV_SEGMENT_STATS
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_WAIT_STATS                    FOR SYS.DV_WAIT_STATS
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_LATCHS                       FOR SYS.DV_LATCHS
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_VM_FUNC_STACK               FOR SYS.DV_VM_FUNC_STACK
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_BUFFER_POOL_STATS      FOR SYS.DV_BUFFER_POOL_STATS
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_BUFFER_PAGE_STATS      FOR SYS.DV_BUFFER_PAGE_STATS
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_BUFFER_INDEX_STATS      FOR SYS.DV_BUFFER_INDEX_STATS
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_XACT_LOCKS             FOR SYS.DV_XACT_LOCKS 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_EMERG_POOL             FOR SYS.DV_EMERG_POOL 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_WHITELIST              FOR SYS.DV_WHITELIST 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_TEMPTABLES             FOR SYS.DV_TEMPTABLES 
/


CREATE OR REPLACE PUBLIC SYNONYM  DV_TEMP_TABLE_STATS             FOR SYS.DV_TEMP_TABLE_STATS 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_TEMP_COLUMN_STATS             FOR SYS.DV_TEMP_COLUMN_STATS 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_TEMP_INDEX_STATS             FOR SYS.DV_TEMP_INDEX_STATS 
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_SESSIONS_EX                  FOR SYS.DV_SESSIONS_EX 
/

CREATE OR REPLACE PUBLIC SYNONYM SYS_DUMMY FOR SYS.SYS_DUMMY
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_USER_ALOCKS                  FOR SYS.DV_USER_ALOCKS 
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_ALL_ALOCKS                  FOR SYS.DV_ALL_ALOCKS 
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_PL_LOCKS                    FOR SYS.DV_PL_LOCKS
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_SESSION_SHARED_LOCKS                  FOR SYS.DV_SESSION_SHARED_LOCKS
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_XACT_SHARED_LOCKS                  FOR SYS.DV_XACT_SHARED_LOCKS
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_DC_RANKINGS                  FOR SYS.DV_DC_RANKINGS
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_RCY_WAIT                  FOR SYS.DV_RCY_WAIT
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_DEBUG_PARAMETERS                  FOR SYS.DV_DEBUG_PARAMETERS
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_PLSQL_LOCKS                  FOR SYS.DV_PLSQL_LOCKS
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_PLSQL_SHARED_LOCKS                  FOR SYS.DV_PLSQL_SHARED_LOCKS
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_BUFFER_ACCESS_STATS                  FOR SYS.DV_BUFFER_ACCESS_STATS
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_BUFFER_RECYCLE_STATS                  FOR SYS.DV_BUFFER_RECYCLE_STATS
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_BACKUP_PROCESS_STATS                  FOR SYS.DV_BACKUP_PROCESS_STATS
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_DATAFILE_LAST_TABLE                  FOR SYS.DV_DATAFILE_LAST_TABLE
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_STATS_RESOURCE                  FOR SYS.DV_STATS_RESOURCE
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_PBL                  FOR SYS.DV_PBL
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_ASYNC_SHRINK_TABLES                  FOR SYS.DV_ASYNC_SHRINK_TABLES
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_CKPT_STATS                  FOR SYS.DV_CKPT_STATS
/

GRANT SELECT ON SYS_DUMMY TO PUBLIC
/

--02
CREATE OR REPLACE VIEW DB_NODE_INFO
AS
  SELECT STATUS, DATABASE_ROLE, DATABASE_CONDITION, CURRENT_SCN FROM SYS.DV_DATABASE
/

CREATE OR REPLACE PUBLIC SYNONYM DB_NODE_INFO FOR SYS.DB_NODE_INFO
/

GRANT SELECT ON DB_NODE_INFO TO PUBLIC
/

CREATE OR REPLACE VIEW SYS.ADM_2PC_PENDING
(FORMAT_ID, GLOBAL_TRAN_ID, BRANCH_ID,OWNER)
AS
  SELECT FORMAT_ID,GLOBAL_TRAN_ID,BRANCH_ID,OWNER FROM SYS.SYS_PENDING_TRANS WHERE DBE_DIAGNOSE.TENANT_CHECK(2, OWNER)
/
CREATE OR REPLACE PUBLIC SYNONYM ADM_2PC_PENDING FOR SYS.ADM_2PC_PENDING
/
CREATE OR REPLACE VIEW ADM_BACKUP_SET
(
  BACKUP_TYPE,
  STAGE,
  STATUS,
  INCREMENTAL_LEVEL,
  TAG,
  SCN,
  DEVICE_TYPE,
  DIR,
  START_TIME,
  BASE_TAG
)
AS
  SELECT DECODE(TYPE, 1, 'FULL', 2, 'INCR', 3, 'LOG', 'INVALID') AS BACKUP_TYPE,
  DECODE(STAGE, 1, 'CTRL', 2, 'HEAD', 3, 'DATA', 4, 'LOG', 'INVALID') AS STAGE,
  DECODE(STATUS, 0, 'SUCCESS', 1, 'DOING', 'FAILED') AS STATUS,
  INCREMENTAL_LEVEL, TAG, SCN, DECODE(DEVICE_TYPE, 0, 'DISK', 1, 'NBU', 'UNKNOWN') AS DEVICE_TYPE,
  DIR, START_TIME, BASE_TAG FROM SYS.SYS_BACKUP_SETS
/
CREATE OR REPLACE PUBLIC SYNONYM ADM_BACKUP_SET FOR SYS.ADM_BACKUP_SET
/

--03
CREATE OR REPLACE VIEW MY_SEGMENTS
(
  SEGMENT_NAME, 
  PARTITION_NAME, 
  SEGMENT_TYPE, 
  TABLESPACE_NAME, 
  BYTES, 
  PAGES, 
  EXTENTS
)
AS
  SELECT T.NAME, '', 'TABLE', TS.NAME, 
  DBE_DIAGNOSE.DBA_SEGSIZE(0, T.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, T.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, T.ENTRY) 
  FROM SYS.DV_ME ME, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS
  WHERE T.USER# = ME.USER_ID AND T.SPACE# = TS.ID
  UNION ALL
  SELECT I.NAME, '', 'INDEX', TS.NAME,
  DBE_DIAGNOSE.DBA_SEGSIZE(0, I.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, I.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, I.ENTRY) 
  FROM SYS.DV_ME ME, SYS.SYS_INDEXES I, SYS.DV_TABLESPACES TS
  WHERE I.USER# = ME.USER_ID AND I.SPACE# = TS.ID
  UNION ALL
  SELECT 'LOB_' || T.NAME || '_' || C.NAME, '', 'LOB', TS.NAME, 
  DBE_DIAGNOSE.DBA_SEGSIZE(0, L.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, L.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, L.ENTRY) 
  FROM SYS.DV_ME ME, SYS.SYS_LOBS L, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.DV_TABLESPACES TS
  WHERE L.USER# = ME.USER_ID AND L.USER# = T.USER# AND L.TABLE# = T.ID AND 
  L.USER# = C.USER# AND L.TABLE# = C.TABLE# AND L.COLUMN# = C.ID AND L.SPACE# = TS.ID
  UNION ALL
  SELECT T.NAME, TP.NAME, 'TABLE', TS.NAME, 
  DBE_DIAGNOSE.DBA_SEGSIZE(0, TP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, TP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, TP.ENTRY) 
  FROM SYS.DV_ME ME, SYS.SYS_TABLES T, SYS.SYS_TABLE_PARTS TP, SYS.DV_TABLESPACES TS 
  WHERE T.PARTITIONED = 1 AND T.USER# = ME.USER_ID AND 
  T.USER# = TP.USER# AND T.ID = TP.TABLE# AND TP.SPACE# = TS.ID
  UNION ALL
  SELECT I.NAME, IP.NAME, 'INDEX', TS.NAME, 
  DBE_DIAGNOSE.DBA_SEGSIZE(0, IP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, IP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, IP.ENTRY) 
  FROM SYS.DV_ME ME, SYS.SYS_INDEXES I, SYS.SYS_INDEX_PARTS IP, SYS.DV_TABLESPACES TS 
  WHERE I.PARTITIONED = 1 AND I.USER# = ME.USER_ID AND 
  I.USER# = IP.USER# AND I.TABLE# = IP.TABLE# AND I.ID = IP.INDEX# AND IP.SPACE# = TS.ID
  UNION ALL
  SELECT 'LOB_' || T.NAME || '_' || C.NAME, 'LOB_' || T.NAME || '_' || C.NAME || '_' || LP.PART#, 
  'LOB', TS.NAME, DBE_DIAGNOSE.DBA_SEGSIZE(0, LP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, LP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, LP.ENTRY) 
  FROM SYS.DV_ME ME, SYS.SYS_LOBS L, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.SYS_LOB_PARTS LP, SYS.DV_TABLESPACES TS
  WHERE L.USER# = ME.USER_ID AND L.USER# = T.USER# AND L.TABLE# = T.ID AND T.PARTITIONED = 1 AND
  L.USER# = C.USER# AND L.TABLE# = C.TABLE# AND L.COLUMN# = C.ID AND
  L.USER# = LP.USER# AND L.TABLE# = LP.TABLE# AND L.COLUMN# = LP.COLUMN# AND LP.SPACE# = TS.ID
  UNION ALL
  SELECT T.NAME, TSUBP.NAME, 'TABLE', TS.NAME, 
  DBE_DIAGNOSE.DBA_SEGSIZE(0, TSUBP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, TSUBP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, TSUBP.ENTRY) 
  FROM SYS.DV_ME ME, SYS.SYS_TABLES T, SYS.SYS_SUB_TABLE_PARTS TSUBP, SYS.DV_TABLESPACES TS
  WHERE T.PARTITIONED = 1 AND T.USER# = ME.USER_ID AND 
  T.USER# = TSUBP.USER# AND T.ID = TSUBP.TABLE# AND TSUBP.SPACE# = TS.ID
  UNION ALL
  SELECT I.NAME, ISUBP.NAME, 'INDEX', TS.NAME, 
  DBE_DIAGNOSE.DBA_SEGSIZE(0, ISUBP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, ISUBP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, ISUBP.ENTRY) 
  FROM SYS.DV_ME ME, SYS.SYS_INDEXES I, SYS.SYS_SUB_INDEX_PARTS ISUBP, SYS.DV_TABLESPACES TS
  WHERE I.PARTITIONED = 1 AND I.USER# = ME.USER_ID AND 
  I.USER# = ISUBP.USER# AND I.TABLE# = ISUBP.TABLE# AND I.ID = ISUBP.INDEX# AND ISUBP.SPACE# = TS.ID
  UNION ALL
  SELECT 'LOB_' || T.NAME || '_' || C.NAME, 'LOB_' || T.NAME || '_' || C.NAME || '_' || LSUBP.PARENT_PART# || '_' || LSUBP.SUBPART#, 
  'LOB', TS.NAME, DBE_DIAGNOSE.DBA_SEGSIZE(0, LSUBP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, LSUBP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, LSUBP.ENTRY) 
  FROM SYS.DV_ME ME, SYS.SYS_LOBS L, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.SYS_SUB_LOB_PARTS LSUBP, SYS.DV_TABLESPACES TS
  WHERE L.USER# = ME.USER_ID AND L.USER# = T.USER# AND L.TABLE# = T.ID AND T.PARTITIONED = 1 AND
  L.USER# = C.USER# AND L.TABLE# = C.TABLE# AND L.COLUMN# = C.ID AND
  L.USER# = LSUBP.USER# AND L.TABLE# = LSUBP.TABLE# AND L.COLUMN# = LSUBP.COLUMN# AND LSUBP.SPACE# = TS.ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_SEGMENTS      FOR SYS.MY_SEGMENTS 
/
GRANT SELECT ON MY_SEGMENTS TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_SEGMENTS
(
  OWNER,
  SEGMENT_NAME, 
  PARTITION_NAME, 
  SEGMENT_TYPE, 
  TABLESPACE_NAME, 
  BYTES, 
  PAGES, 
  EXTENTS
)
AS
  SELECT U.NAME, T.NAME, '', 'TABLE', TS.NAME, 
  DBE_DIAGNOSE.DBA_SEGSIZE(0, T.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, T.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, T.ENTRY) 
  FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS
  WHERE T.USER# = U.ID AND T.SPACE# = TS.ID
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT  U.NAME, I.NAME, '', 'INDEX', TS.NAME,
  DBE_DIAGNOSE.DBA_SEGSIZE(0, I.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, I.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, I.ENTRY) 
  FROM SYS.SYS_USERS U, SYS.SYS_INDEXES I, SYS.DV_TABLESPACES TS
  WHERE I.USER# = U.ID AND I.SPACE# = TS.ID
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, 'LOB_' || T.NAME || '_' || C.NAME, '', 'LOB', TS.NAME, 
  DBE_DIAGNOSE.DBA_SEGSIZE(0, L.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, L.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, L.ENTRY) 
  FROM SYS.SYS_USERS U, SYS.SYS_LOBS L, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.DV_TABLESPACES TS
  WHERE L.USER# = U.ID AND L.USER# = T.USER# AND L.TABLE# = T.ID AND 
  L.USER# = C.USER# AND L.TABLE# = C.TABLE# AND L.COLUMN# = C.ID AND L.SPACE# = TS.ID
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, T.NAME, TP.NAME, 'TABLE', TS.NAME, 
  DBE_DIAGNOSE.DBA_SEGSIZE(0, TP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, TP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, TP.ENTRY) 
  FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_TABLE_PARTS TP, SYS.DV_TABLESPACES TS
  WHERE T.PARTITIONED = 1 AND T.USER# = U.ID AND 
  T.USER# = TP.USER# AND T.ID = TP.TABLE# AND TP.SPACE# = TS.ID
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, I.NAME, IP.NAME, 'INDEX', TS.NAME, 
  DBE_DIAGNOSE.DBA_SEGSIZE(0, IP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, IP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, IP.ENTRY) 
  FROM SYS.SYS_USERS U, SYS.SYS_INDEXES I, SYS.SYS_INDEX_PARTS IP, SYS.DV_TABLESPACES TS
  WHERE I.PARTITIONED = 1 AND I.USER# = U.ID AND 
  I.USER# = IP.USER# AND I.TABLE# = IP.TABLE# AND I.ID = IP.INDEX# AND IP.SPACE# = TS.ID
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, 'LOB_' || T.NAME || '_' || C.NAME, 'LOB_' || T.NAME || '_' || C.NAME || '_' || LP.PART#, 
  'LOB', TS.NAME, DBE_DIAGNOSE.DBA_SEGSIZE(0, LP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, LP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, LP.ENTRY) 
  FROM SYS.SYS_USERS U, SYS.SYS_LOBS L, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.SYS_LOB_PARTS LP, SYS.DV_TABLESPACES TS
  WHERE L.USER# = U.ID AND L.USER# = T.USER# AND L.TABLE# = T.ID AND T.PARTITIONED = 1 AND
  L.USER# = C.USER# AND L.TABLE# = C.TABLE# AND L.COLUMN# = C.ID AND
  L.USER# = LP.USER# AND L.TABLE# = LP.TABLE# AND L.COLUMN# = LP.COLUMN# AND LP.SPACE# = TS.ID
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, T.NAME, TSUBP.NAME, 'TABLE', TS.NAME, 
  DBE_DIAGNOSE.DBA_SEGSIZE(0, TSUBP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, TSUBP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, TSUBP.ENTRY) 
  FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_SUB_TABLE_PARTS TSUBP, SYS.DV_TABLESPACES TS
  WHERE T.PARTITIONED = 1 AND T.USER# = U.ID AND 
  T.USER# = TSUBP.USER# AND T.ID = TSUBP.TABLE# AND TSUBP.SPACE# = TS.ID
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, I.NAME, ISUBP.NAME, 'INDEX', TS.NAME, 
  DBE_DIAGNOSE.DBA_SEGSIZE(0, ISUBP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, ISUBP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, ISUBP.ENTRY) 
  FROM SYS.SYS_USERS U, SYS.SYS_INDEXES I, SYS.SYS_SUB_INDEX_PARTS ISUBP, SYS.DV_TABLESPACES TS
  WHERE I.PARTITIONED = 1 AND I.USER# = U.ID AND 
  I.USER# = ISUBP.USER# AND I.TABLE# = ISUBP.TABLE# AND I.ID = ISUBP.INDEX# AND ISUBP.SPACE# = TS.ID
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, 'LOB_' || T.NAME || '_' || C.NAME, 'LOB_' || T.NAME || '_' || C.NAME || '_' || LSUBP.PARENT_PART# || '_' || LSUBP.SUBPART#, 
  'LOB', TS.NAME, DBE_DIAGNOSE.DBA_SEGSIZE(0, LSUBP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(1, LSUBP.ENTRY), DBE_DIAGNOSE.DBA_SEGSIZE(2, LSUBP.ENTRY) 
  FROM SYS.SYS_USERS U, SYS.SYS_LOBS L, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.SYS_SUB_LOB_PARTS LSUBP, SYS.DV_TABLESPACES TS
  WHERE L.USER# = U.ID AND L.USER# = T.USER# AND L.TABLE# = T.ID AND T.PARTITIONED = 1 AND
  L.USER# = C.USER# AND L.TABLE# = C.TABLE# AND L.COLUMN# = C.ID AND
  L.USER# = LSUBP.USER# AND L.TABLE# = LSUBP.TABLE# AND L.COLUMN# = LSUBP.COLUMN# AND LSUBP.SPACE# = TS.ID
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_SEGMENTS       FOR SYS.ADM_SEGMENTS 
/
--04
CREATE OR REPLACE VIEW ADM_TABLES
(
  OWNER, 
  TABLE_NAME,
  TABLE_ID, 
  TABLESPACE_NAME,
  COLUMN_COUNT,
  INDEX_COUNT,
  PARTITIONED,
  CREATED_TIME,
  LAST_DDL_TIME,
  PCT_FREE,
  INI_TRANS,
  MAX_TRANS, 
  BYTES,
  PAGES,
  EXTENTS,
  NUM_ROWS,
  BLOCKS,
  EMPTY_BLOCKS,
  AVG_SPACE,
  CHAIN_CNT,
  AVG_ROW_LEN,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  STATUS,
  TEMPORARY,
  APPENDONLY,
  TABLE_TYPE,
  CR_MODE,
  ROW_FORMAT,
  NOLOGGING_INSERT,
  COMPRESS_ALGO
) 
AS 
  SELECT U.NAME, T.NAME, T.ID,
  TS.NAME, T.COLS, T.INDEXES,
  DECODE(T.PARTITIONED,1,'Y','N'),   
  SCN2DATE(T.ORG_SCN), SCN2DATE(T.CHG_SCN), T.PCTFREE, T.INITRANS, 255,
  DECODE(T.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(0, T.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_TABSIZE(0,U.NAME,'"'||T.NAME||'"')), 
  DECODE(T.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(1, T.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_TABSIZE(1,U.NAME,'"'||T.NAME||'"')),
  DECODE(T.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(2, T.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_TABSIZE(2,U.NAME,'"'||T.NAME||'"')),
  T.NUM_ROWS, T.BLOCKS, T.EMPTY_BLOCKS, NULL::NUMBER, NULL::NUMBER, T.AVG_ROW_LEN,
  T.SAMPLESIZE, T.ANALYZETIME,
  'VALID', 
  DECODE(T.TYPE, 0, 'N', 1, 'N', 2, 'Y', 3, 'Y', 4, 'Y', 5, 'N'),  
  DECODE(T.APPENDONLY, 1, 'Y', 'N'),
  DECODE(T.TYPE, 0, 'HEAP', 1, 'IOT', 2, 'TRANS_TEMP', 3, 'SESSION_TEMP', 4, 'NOLOGGING', 5, 'EXTERNAL'),
  DECODE(T.CR_MODE, 0, 'ROW', 1, 'PAGE', NULL),
  DECODE(T.FLAG & 1, 1, 'CSF', 'ASF'),
  DECODE(T.FLAG & 4, 4, 'YES', 'NO'),
  NVL((select DECODE(CO.COMPRESS_ALGO, 0, 'NONE', 1, 'ZLIB', 2, 'ZSTD', 3, 'LZ4', 'NONE') from SYS.SYS_COMPRESS_OBJECTS CO where CO.ORG_SCN = T.ORG_SCN AND CO.OBJECT_TYPE = 0), 'NONE')
  FROM SYS.SYS_USERS U, SYS.DV_TABLESPACES TS, SYS.SYS_TABLES T
  WHERE T.USER# = U.ID AND T.SPACE# = TS.ID AND T.RECYCLED = 0
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_TABLES         FOR SYS.ADM_TABLES 
/
CREATE OR REPLACE VIEW DB_TABLES
(
  OWNER, 
  TABLE_NAME,
  TABLE_ID, 
  TABLESPACE_NAME,
  COLUMN_COUNT,
  INDEX_COUNT,
  PARTITIONED,
  CREATED_TIME,
  LAST_DDL_TIME,
  PCT_FREE,
  INI_TRANS,
  MAX_TRANS, 
  BYTES,
  PAGES,
  EXTENTS,
  NUM_ROWS,
  BLOCKS,
  EMPTY_BLOCKS,
  AVG_SPACE,
  CHAIN_CNT,
  AVG_ROW_LEN,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  STATUS,
  TEMPORARY,
  APPENDONLY,
  TABLE_TYPE,
  CR_MODE,
  ROW_FORMAT,
  NOLOGGING_INSERT,
  COMPRESS_ALGO
) 
AS 
  SELECT U.NAME, T.NAME, T.ID,
  TS.NAME, T.COLS, T.INDEXES, 
  DECODE(T.PARTITIONED,1,'Y','N'),  
  SCN2DATE(T.ORG_SCN), SCN2DATE(T.CHG_SCN), T.PCTFREE, T.INITRANS, 255,
  DECODE(T.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(0, T.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_TABSIZE(0,U.NAME,'"'||T.NAME||'"')), 
  DECODE(T.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(1, T.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_TABSIZE(1,U.NAME,'"'||T.NAME||'"')),
  DECODE(T.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(2, T.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_TABSIZE(2,U.NAME,'"'||T.NAME||'"')),
  T.NUM_ROWS, T.BLOCKS, T.EMPTY_BLOCKS, NULL::NUMBER, NULL::NUMBER, T.AVG_ROW_LEN,
  T.SAMPLESIZE, T.ANALYZETIME,
  'VALID', 
  DECODE(T.TYPE, 0, 'N', 1, 'N', 2, 'Y', 3, 'Y', 4, 'Y', 5, 'N'), 
  DECODE(T.APPENDONLY, 1, 'Y', 'N'),
  DECODE(T.TYPE, 0, 'HEAP', 1, 'IOT', 2, 'TRANS_TEMP', 3, 'SESSION_TEMP', 4, 'NOLOGGING', 5, 'EXTERNAL'),
  DECODE(T.CR_MODE, 0, 'ROW', 1, 'PAGE', NULL),
  DECODE(T.FLAG & 1, 1, 'CSF', 'ASF'),
  DECODE(T.FLAG & 4, 4, 'YES', 'NO'),
  NVL((select DECODE(CO.COMPRESS_ALGO, 0, 'NONE', 1, 'ZLIB', 2, 'ZSTD', 3, 'LZ4', 'NONE') from SYS.SYS_COMPRESS_OBJECTS CO where CO.ORG_SCN = T.ORG_SCN AND CO.OBJECT_TYPE = 0), 'NONE')
  FROM SYS.SYS_USERS U, SYS.DV_TABLESPACES TS, SYS.SYS_TABLES T
  WHERE T.USER# = U.ID AND T.SPACE# = TS.ID AND T.RECYCLED = 0
    and (user = 'SYS' or  
        U.NAME = user or 
        DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_TABLES         FOR SYS.DB_TABLES 
/
GRANT SELECT ON DB_TABLES TO PUBLIC
/

CREATE OR REPLACE VIEW DB_DBLINK_TABLES
(
  OWNER, 
  TABLE_NAME,
  OWNER_ID,
  TABLE_ID, 
  COLUMN_COUNT,
  INDEX_COUNT
) 
AS 
  SELECT U.NAME, T.NAME, U.ID, T.ID, T.COLS, T.INDEXES
  FROM SYS.SYS_USERS U, SYS.SYS_TABLES T
  WHERE T.USER# = U.ID AND T.RECYCLED = 0 
  and (U.NAME = user or 
    user = 'SYS' or
    DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_DBLINK_TABLES         FOR SYS.DB_DBLINK_TABLES 
/
GRANT SELECT ON DB_DBLINK_TABLES TO PUBLIC
/
--05
CREATE OR REPLACE VIEW ADM_REDACTION_POLICIES
(
  USER_NAME,
  OBJECT_NAME, 
  COL_NAME, 
  RULE_NAME, 
  TYPE_NAME, 
  PARAM
)
AS
  SELECT U.NAME, T.NAME, C.NAME, D.RULE_NAME, D.TYPE_NAME, D.PARAM
  FROM SYS.SYS_DDM D, SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C
  WHERE U.ID = D.USER# AND T.ID = D.TABLE# AND C.TABLE# = D.TABLE# AND C.USER# = D.USER# AND C.ID = D.COLUMN# AND T.USER# = U.ID
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_REDACTION_POLICIES   FOR SYS.ADM_REDACTION_POLICIES 
/

CREATE OR REPLACE VIEW MY_REDACTION_POLICIES
(
  USER_NAME,
  OBJECT_NAME, 
  COL_NAME, 
  RULE_NAME, 
  TYPE_NAME, 
  PARAM
)
AS
  SELECT U.NAME, T.NAME, C.NAME, D.RULE_NAME, D.TYPE_NAME, D.PARAM
  FROM SYS.SYS_DDM D, SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.DV_ME ME
  WHERE U.ID = D.USER# AND T.ID = D.TABLE# AND C.TABLE# = D.TABLE# AND C.USER# = D.USER# AND C.ID = D.COLUMN# AND T.USER# = U.ID AND D.USER# = ME.USER_ID
/  
CREATE OR REPLACE PUBLIC SYNONYM  MY_REDACTION_POLICIES    FOR SYS.MY_REDACTION_POLICIES 
/
GRANT SELECT ON MY_REDACTION_POLICIES TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_POLICIES
(
  OBJECT_OWNER,
  OBJECT_NAME,
  POLICY_NAME,
  PF_OWNER,
  FUNCTION,
  SEL,
  INS,
  UPD,
  DEL,
  CHK_OPTION,
  ENABLE,
  LONG_PREDICATE
)
AS
  SELECT U.NAME, P.OBJ_NAME, P.PNAME, P.PF_SCHEMA, P.PF_NAME, 
  DECODE(bitand(P.STMT_TYPE, 1), 0, 'NO', 1, 'YES'),
  DECODE(bitand(P.STMT_TYPE, 2), 0, 'NO', 2, 'YES'),
  DECODE(bitand(P.STMT_TYPE, 4), 0, 'NO', 4, 'YES'),
  DECODE(bitand(P.STMT_TYPE, 8), 0, 'NO', 8, 'YES'),
  DECODE(P.CHK_OPTION, 0, 'NO', 1, 'YES'),
  DECODE(P.ENABLE, 0, 'NO', 1, 'YES'),
  DECODE(P.LONG_PREDICATE, 0, 'NO', 1, 'YES') 
  FROM SYS.SYS_POLICIES P, SYS.SYS_USERS U 
  WHERE U.ID = P.OBJ_SCHEMA_ID
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_POLICIES   FOR SYS.ADM_POLICIES 
/
CREATE OR REPLACE VIEW MY_POLICIES
(
  OBJECT_OWNER,
  OBJECT_NAME,
  POLICY_NAME,
  PF_OWNER,
  FUNCTION,
  SEL,
  INS,
  UPD,
  DEL,
  CHK_OPTION,
  ENABLE,
  LONG_PREDICATE
)
AS
  SELECT U.NAME, P.OBJ_NAME, P.PNAME, P.PF_SCHEMA, P.PF_NAME, 
  DECODE(bitand(P.STMT_TYPE, 1), 0, 'NO', 1, 'YES'),
  DECODE(bitand(P.STMT_TYPE, 2), 0, 'NO', 2, 'YES'),
  DECODE(bitand(P.STMT_TYPE, 4), 0, 'NO', 4, 'YES'),
  DECODE(bitand(P.STMT_TYPE, 8), 0, 'NO', 8, 'YES'),
  DECODE(P.CHK_OPTION, 0, 'NO', 1, 'YES'),
  DECODE(P.ENABLE, 0, 'NO', 1, 'YES'),
  DECODE(P.LONG_PREDICATE, 0, 'NO', 1, 'YES') 
  FROM SYS.SYS_POLICIES P, SYS.SYS_USERS U, SYS.DV_ME ME 
  WHERE U.ID = P.OBJ_SCHEMA_ID AND P.OBJ_SCHEMA_ID = ME.USER_ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_POLICIES    FOR SYS.MY_POLICIES 
/
GRANT SELECT ON MY_POLICIES TO PUBLIC
/
--06
CREATE OR REPLACE VIEW ADM_DBLINK_TABLES
(
  OWNER, 
  TABLE_NAME,
  OWNER_ID,
  TABLE_ID, 
  COLUMN_COUNT,
  INDEX_COUNT
) 
AS 
  SELECT U.NAME, T.NAME, U.ID, T.ID, T.COLS, T.INDEXES
  FROM SYS.SYS_USERS U, SYS.SYS_TABLES T
  WHERE T.USER# = U.ID AND T.RECYCLED = 0
  AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_DBLINK_TABLES  FOR SYS.ADM_DBLINK_TABLES 
/
CREATE OR REPLACE VIEW MY_TABLES
(
  TABLE_NAME,
  TABLE_ID, 
  TABLESPACE_NAME,
  COLUMN_COUNT,
  INDEX_COUNT,
  PARTITIONED,
  CREATED_TIME,
  LAST_DDL_TIME,
  PCT_FREE,
  INI_TRANS,
  MAX_TRANS,
  BYTES,
  PAGES,
  EXTENTS,
  NUM_ROWS,
  BLOCKS,
  EMPTY_BLOCKS,
  AVG_SPACE,
  CHAIN_CNT,
  AVG_ROW_LEN,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  STATUS,
  TEMPORARY,
  APPENDONLY,
  TABLE_TYPE,
  CR_MODE,
  ROW_FORMAT,
  NOLOGGING_INSERT,
  COMPRESS_ALGO
) 
AS 
  SELECT T.NAME, T.ID,
  TS.NAME, T.COLS, T.INDEXES, 
  DECODE(T.PARTITIONED,1,'Y','N'),  
  SCN2DATE(T.ORG_SCN), SCN2DATE(T.CHG_SCN), T.PCTFREE, T.INITRANS, 255,
  DECODE(T.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(0, T.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_TABSIZE(0,ME.USER_NAME,'"'||T.NAME||'"')), 
  DECODE(T.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(1, T.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_TABSIZE(1,ME.USER_NAME,'"'||T.NAME||'"')),
  DECODE(T.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(2, T.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_TABSIZE(2,ME.USER_NAME,'"'||T.NAME||'"')),
  T.NUM_ROWS, T.BLOCKS, T.EMPTY_BLOCKS, NULL::NUMBER, NULL::NUMBER, T.AVG_ROW_LEN,
  T.SAMPLESIZE, T.ANALYZETIME,
  'VALID', 
  DECODE(T.TYPE, 0, 'N', 1, 'N', 2, 'Y', 3, 'Y', 4, 'Y', 5, 'N'),
  DECODE(T.APPENDONLY, 1, 'Y', 'N'),
  DECODE(T.TYPE, 0, 'HEAP', 1, 'IOT', 2, 'TRANS_TEMP', 3, 'SESSION_TEMP', 4, 'NOLOGGING', 5, 'EXTERNAL'),
  DECODE(T.CR_MODE, 0, 'ROW', 1, 'PAGE', NULL),
  DECODE(T.FLAG & 1, 1, 'CSF', 'ASF'),
  DECODE(T.FLAG & 4, 4, 'YES', 'NO'),
  NVL((select DECODE(CO.COMPRESS_ALGO, 0, 'NONE', 1, 'ZLIB', 2, 'ZSTD', 3, 'LZ4', 'NONE') from SYS.SYS_COMPRESS_OBJECTS CO where CO.ORG_SCN = T.ORG_SCN AND CO.OBJECT_TYPE = 0), 'NONE')
  FROM SYS.DV_ME ME, SYS.DV_TABLESPACES TS, SYS.SYS_TABLES T
  WHERE T.USER# = ME.USER_ID AND T.SPACE# =TS.ID AND T.RECYCLED = 0
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_TABLES        FOR SYS.MY_TABLES 
/
GRANT SELECT ON MY_TABLES TO PUBLIC
/
CREATE OR REPLACE VIEW DB_TAB_COLS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  DATA_TYPE,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE,
  NULLABLE,
  COLUMN_ID,
  DATA_DEFAULT,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  CHAR_LENGTH,
  CHAR_USED,
  HISTOGRAM,
  IS_JSONB
) 
AS
  SELECT U.NAME, T.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''),
  C.BYTES, C.PRECISION,  C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, 
  C.DEFAULT_TEXT, C.NUM_DISTINCT, C.LOW_VALUE, C.HIGH_VALUE, 0, NULL, C.HISTOGRAM,
  DECODE(C.FLAGS & 2048, 2048, 'TRUE', 'FALSE') 
  FROM SYS.SYS_USERS U, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
  WHERE C.TABLE# = T.ID AND C.USER# = T.USER# AND T.USER# = U.ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0
    AND TYPE_ID2NAME(C.DATATYPE) NOT IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
    and (U.NAME = user or 
        user = 'SYS' or    
        DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, T.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''),
  C.BYTES, C.PRECISION,  C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, 
  C.DEFAULT_TEXT, C.NUM_DISTINCT, C.LOW_VALUE, C.HIGH_VALUE, C.BYTES, DECODE(C.FLAGS & 32, 32, 'C', 'B'), C.HISTOGRAM,
  DECODE(C.FLAGS & 2048, 2048, 'TRUE', 'FALSE') 
  FROM SYS.SYS_USERS U, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
  WHERE C.TABLE# = T.ID AND C.USER# = T.USER# AND T.USER# = U.ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0
    AND TYPE_ID2NAME(C.DATATYPE) IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
    and (U.NAME = user or  
        user = 'SYS' or    
        DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_TAB_COLS       FOR SYS.DB_TAB_COLS 
/
GRANT SELECT ON DB_TAB_COLS TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_TAB_COLS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  DATA_TYPE,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE,
  NULLABLE,
  COLUMN_ID,
  DATA_DEFAULT,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  CHAR_LENGTH,
  CHAR_USED,
  HISTOGRAM,
  IS_JSONB
) 
AS
  SELECT U.NAME, T.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''),
  C.BYTES, C.PRECISION,  C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, 
  C.DEFAULT_TEXT, C.NUM_DISTINCT, C.LOW_VALUE, C.HIGH_VALUE, 0, NULL, C.HISTOGRAM,
  DECODE(C.FLAGS & 2048, 2048, 'TRUE', 'FALSE') 
  FROM SYS.SYS_USERS U, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
  WHERE C.TABLE# = T.ID AND C.USER# = T.USER# AND T.USER# = U.ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0
    AND TYPE_ID2NAME(C.DATATYPE) NOT IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, T.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''),
  C.BYTES, C.PRECISION,  C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, 
  C.DEFAULT_TEXT, C.NUM_DISTINCT, C.LOW_VALUE, C.HIGH_VALUE, C.BYTES, DECODE(C.FLAGS & 32, 32, 'C', 'B'), C.HISTOGRAM,
  DECODE(C.FLAGS & 2048, 2048, 'TRUE', 'FALSE') 
  FROM SYS.SYS_USERS U, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
  WHERE C.TABLE# = T.ID AND C.USER# = T.USER# AND T.USER# = U.ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0
    AND TYPE_ID2NAME(C.DATATYPE) IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_TAB_COLS     FOR SYS.ADM_TAB_COLS
/

--07
CREATE OR REPLACE VIEW MY_PART_STORE
(
    NAME,
    OBJECT_TYPE,
    POSITION,
    TABLESPACE_NAME
)
AS
SELECT T.NAME,
       'TABLE',
       P.POSITION#,
       TS.NAME
   FROM SYS.DV_ME U, SYS.SYS_PART_STORES P, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS
   WHERE P.INDEX# = -1
   AND P.USER# = U.USER_ID
   AND P.USER# = T.USER# AND P.TABLE# = T.ID
   AND P.SPACE# = TS.ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_PART_STORE       FOR SYS.MY_PART_STORE
/
GRANT SELECT ON MY_PART_STORE TO PUBLIC
/

CREATE OR REPLACE VIEW DB_PART_STORE
(
    OWNER,
    NAME,
    OBJECT_TYPE,
    POSITION,
    TABLESPACE_NAME
)
AS
SELECT U.NAME,
       T.NAME,
       'TABLE',
       P.POSITION#,
       TS.NAME
  FROM SYS.SYS_USERS U, SYS.SYS_PART_STORES P, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS
 WHERE P.INDEX# = -1
   AND P.USER# = U.ID
   AND P.USER# = T.USER# 
   AND P.TABLE# = T.ID
   AND P.SPACE# = TS.ID
   AND T.RECYCLED = 0
   AND (U.NAME = user or 
        user = 'SYS' or
        DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
   AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_PART_STORE       FOR SYS.DB_PART_STORE
/
GRANT SELECT ON DB_PART_STORE TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_PART_STORE
(
    OWNER,
    NAME,
    OBJECT_TYPE,
    POSITION,
    TABLESPACE_NAME
)
AS
SELECT U.NAME,
       T.NAME,
       'TABLE',
       P.POSITION#,
       TS.NAME
  FROM SYS.SYS_USERS U, SYS.SYS_PART_STORES P, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS
 WHERE P.INDEX# = -1
   AND P.USER# = U.ID
   AND P.USER# = T.USER# 
   AND P.TABLE# = T.ID
   AND P.SPACE# = TS.ID
   AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_PART_STORE       FOR SYS.ADM_PART_STORE 
/
--08
CREATE OR REPLACE VIEW MY_PART_TABLES
(
  TABLE_NAME,
  PARTITIONING_TYPE,
  PARTITION_COUNT,
  PARTITIONING_KEY_COUNT,
  DEF_TABLESPACE_NAME,
  INTERVAL,
  STATUS,
  SUBPARTITION_TYPE
)
AS
SELECT T.NAME,
       DECODE(P.PARTTYPE, 0, 'INVALID', 1, 'RANGE', 2, 'LIST', 3, 'HASH'),
       P.PARTCNT#,
       PARTKEYS#,
       TS.NAME,
       P.INTERVAL,
       'VALID',
       DECODE(P.SUBPARTTYPE, 0, 'INVALID', 1, 'RANGE', 2, 'LIST', 3, 'HASH')
   FROM SYS.DV_ME U, SYS.SYS_PART_OBJECTS P, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS
   WHERE P.INDEX# = -1
   AND P.USER# = U.USER_ID
   AND P.USER# = T.USER# AND P.TABLE# = T.ID
   AND T.SPACE# = TS.ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_PART_TABLES       FOR SYS.MY_PART_TABLES
/
GRANT SELECT ON MY_PART_TABLES TO PUBLIC
/
CREATE OR REPLACE VIEW DB_PART_TABLES
(
  OWNER,
  TABLE_NAME,
  PARTITIONING_TYPE,
  PARTITION_COUNT,
  PARTITIONING_KEY_COUNT,
  DEF_TABLESPACE_NAME,
  INTERVAL,
  STATUS,
  SUBPARTITION_TYPE
)
AS
SELECT U.NAME,
       T.NAME,
       DECODE(P.PARTTYPE, 0, 'INVALID', 1, 'RANGE', 2, 'LIST', 3, 'HASH'),
       P.PARTCNT#,
       PARTKEYS#,
       TS.NAME,
       P.INTERVAL,
       'VALID',
       DECODE(P.SUBPARTTYPE, 0, 'INVALID', 1, 'RANGE', 2, 'LIST', 3, 'HASH')
 FROM SYS.SYS_USERS U, SYS.SYS_PART_OBJECTS P, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS
 WHERE T.RECYCLED = 0
   AND P.INDEX# = -1
   AND P.USER# = U.ID
   AND P.USER# = T.USER# AND P.TABLE# = T.ID
   AND T.SPACE# = TS.ID
   AND (U.NAME = user or 
        user = 'SYS' or
        DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
   AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_PART_TABLES       FOR SYS.DB_PART_TABLES
/
GRANT SELECT ON DB_PART_TABLES TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_PART_TABLES
(
  OWNER,
  TABLE_NAME,
  PARTITIONING_TYPE,
  PARTITION_COUNT,
  PARTITIONING_KEY_COUNT,
  DEF_TABLESPACE_NAME,
  INTERVAL,
  STATUS,
  SUBPARTITION_TYPE
)
AS
SELECT U.NAME,
       T.NAME,
       DECODE(P.PARTTYPE, 0, 'INVALID', 1, 'RANGE', 2, 'LIST', 3, 'HASH'),
       P.PARTCNT#,
       PARTKEYS#,
       TS.NAME,
       P.INTERVAL,
       'VALID',
       DECODE(P.SUBPARTTYPE, 0, 'INVALID', 1, 'RANGE', 2, 'LIST', 3, 'HASH')
 FROM SYS.SYS_USERS U, SYS.SYS_PART_OBJECTS P, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS
 WHERE P.INDEX# = -1
   AND P.USER# = U.ID
   AND P.USER# = T.USER# AND P.TABLE# = T.ID
   AND T.SPACE# = TS.ID
   AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_PART_TABLES       FOR SYS.ADM_PART_TABLES 
/
--09
CREATE OR REPLACE VIEW DB_PART_KEY_COLUMNS
(
  OWNER,
  NAME,
  OBJECT_TYPE,
  COLUMN_NAME,
  COLUMN_POSITION
)
AS
  SELECT U.NAME,
         T.NAME, 
         'TABLE',
         C.NAME,
         P.POSITION# + 1
    FROM SYS.SYS_USERS U, SYS.SYS_PART_COLUMNS P, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
   WHERE T.RECYCLED = 0
     AND P.USER# = U.ID
     AND P.TABLE#= T.ID
     AND P.USER# = T.USER#
     AND P.USER# = C.USER#
     AND P.TABLE#= C.TABLE#
     AND P.COLUMN# = C.ID
     AND (U.NAME = user or 
          user = 'SYS' or
          DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
     AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_PART_KEY_COLUMNS       FOR SYS.DB_PART_KEY_COLUMNS 
/
GRANT SELECT ON DB_PART_KEY_COLUMNS TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_PART_KEY_COLUMNS
(
  OWNER,
  NAME,
  OBJECT_TYPE,
  COLUMN_NAME,
  COLUMN_POSITION
)
AS
  SELECT U.NAME,
         T.NAME, 
         'TABLE',
         C.NAME,
         P.POSITION# + 1
     FROM SYS.SYS_USERS U, SYS.SYS_PART_COLUMNS P, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
     WHERE P.USER# = U.ID
     AND P.TABLE#= T.ID
     AND P.USER# = T.USER#
     AND P.USER# = C.USER#
     AND P.TABLE#= C.TABLE#
     AND P.COLUMN# = C.ID
     AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_PART_KEY_COLUMNS       FOR SYS.ADM_PART_KEY_COLUMNS 
/

CREATE OR REPLACE VIEW MY_PART_KEY_COLUMNS
(
  NAME,
  OBJECT_TYPE,
  COLUMN_NAME,
  COLUMN_POSITION
)
AS
  SELECT T.NAME, 
         'TABLE',
         C.NAME,
         P.POSITION# + 1
     FROM SYS.DV_ME B, SYS.SYS_PART_COLUMNS P, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
     WHERE P.USER# = B.USER_ID
     AND P.TABLE#= T.ID
     AND P.USER# = T.USER#
     AND P.USER# = C.USER#
     AND P.TABLE#= C.TABLE#
     AND P.COLUMN# = C.ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_PART_KEY_COLUMNS       FOR SYS.MY_PART_KEY_COLUMNS 
/
GRANT SELECT ON MY_PART_KEY_COLUMNS TO PUBLIC
/
CREATE OR REPLACE VIEW DB_SUBPART_KEY_COLUMNS
(
  OWNER,
  NAME,
  OBJECT_TYPE,
  COLUMN_NAME,
  COLUMN_POSITION
)
AS
  SELECT U.NAME,
         T.NAME, 
         'TABLE',
         C.NAME,
         SUBP.POSITION# + 1
    FROM SYS.SYS_USERS U, SYS.SYS_SUB_PART_COLUMNS SUBP, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
   WHERE T.RECYCLED = 0
     AND SUBP.USER# = U.ID
     AND SUBP.TABLE#= T.ID
     AND SUBP.USER# = T.USER#
     AND SUBP.USER# = C.USER#
     AND SUBP.TABLE#= C.TABLE#
     AND SUBP.COLUMN# = C.ID
     AND (U.NAME = user or 
          user = 'SYS' or
          DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
     AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_SUBPART_KEY_COLUMNS       FOR SYS.DB_SUBPART_KEY_COLUMNS 
/
GRANT SELECT ON DB_SUBPART_KEY_COLUMNS TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_SUBPART_KEY_COLUMNS
(
  OWNER,
  NAME,
  OBJECT_TYPE,
  COLUMN_NAME,
  COLUMN_POSITION
)
AS
  SELECT U.NAME,
         T.NAME, 
         'TABLE',
         C.NAME,
         SUBP.POSITION# + 1
     FROM SYS.SYS_USERS U, SYS.SYS_SUB_PART_COLUMNS SUBP, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
     WHERE SUBP.USER# = U.ID
     AND SUBP.TABLE#= T.ID
     AND SUBP.USER# = T.USER#
     AND SUBP.USER# = C.USER#
     AND SUBP.TABLE#= C.TABLE#
     AND SUBP.COLUMN# = C.ID
     AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_SUBPART_KEY_COLUMNS       FOR SYS.ADM_SUBPART_KEY_COLUMNS 
/

CREATE OR REPLACE VIEW MY_SUBPART_KEY_COLUMNS
(
  NAME,
  OBJECT_TYPE,
  COLUMN_NAME,
  COLUMN_POSITION
)
AS
  SELECT T.NAME, 
         'TABLE',
         C.NAME,
         SUBP.POSITION# + 1
     FROM SYS.DV_ME B, SYS.SYS_SUB_PART_COLUMNS SUBP, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
     WHERE SUBP.USER# = B.USER_ID
     AND SUBP.TABLE#= T.ID
     AND SUBP.USER# = T.USER#
     AND SUBP.USER# = C.USER#
     AND SUBP.TABLE#= C.TABLE#
     AND SUBP.COLUMN# = C.ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_SUBPART_KEY_COLUMNS       FOR SYS.MY_SUBPART_KEY_COLUMNS 
/
GRANT SELECT ON MY_SUBPART_KEY_COLUMNS TO PUBLIC
/
--10
CREATE OR REPLACE VIEW MY_TAB_COLS
(
  TABLE_NAME,
  COLUMN_NAME,
  DATA_TYPE,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE,
  NULLABLE,
  COLUMN_ID,
  DATA_DEFAULT,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  CHAR_LENGTH,
  CHAR_USED,
  HISTOGRAM,
  IS_JSONB
) 
AS
  SELECT T.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''),
  C.BYTES, C.PRECISION,  C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, 
  C.DEFAULT_TEXT, C.NUM_DISTINCT, C.LOW_VALUE, C.HIGH_VALUE, 0, NULL, C.HISTOGRAM,
  DECODE(C.FLAGS & 2048, 2048, 'TRUE', 'FALSE') 
  FROM SYS.DV_ME M, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
  WHERE C.TABLE# = T.ID AND C.USER# = T.USER# AND T.USER# = M.USER_ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0 
    AND TYPE_ID2NAME(C.DATATYPE) NOT IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
  UNION ALL
  SELECT T.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''),
  C.BYTES, C.PRECISION,  C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, 
  C.DEFAULT_TEXT, C.NUM_DISTINCT, C.LOW_VALUE, C.HIGH_VALUE, C.BYTES, DECODE(C.FLAGS & 32, 32, 'C', 'B'), C.HISTOGRAM,
  DECODE(C.FLAGS & 2048, 2048, 'TRUE', 'FALSE') 
  FROM SYS.DV_ME M, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
  WHERE C.TABLE# = T.ID AND C.USER# = T.USER# AND T.USER# = M.USER_ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0 
    AND TYPE_ID2NAME(C.DATATYPE) IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_TAB_COLS      FOR SYS.MY_TAB_COLS
/
GRANT SELECT ON MY_TAB_COLS TO PUBLIC
/
CREATE OR REPLACE VIEW MY_TAB_COLUMNS
(
  TABLE_NAME,
  COLUMN_NAME,
  DATA_TYPE,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE,
  NULLABLE,
  COLUMN_ID,
  DATA_DEFAULT,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  NUM_NULLS,
  NUM_BUCKETS,
  CHAR_LENGTH,
  CHAR_USED,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  HISTOGRAM,
  AUTO_INCREMENT
) 
AS
  SELECT T.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''),
         C.BYTES, C.PRECISION,  C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, 
         C.DEFAULT_TEXT, C.NUM_DISTINCT, C.LOW_VALUE, C.HIGH_VALUE, HH.NULL_NUM, HH.BUCKET_NUM, 
         0, NULL::CHAR, HH.SPARE3, HH.ANALYZE_TIME, C.HISTOGRAM,DECODE(C.FLAGS & 8, 0, 'N', 'Y')
  FROM SYS.DV_ME M JOIN SYS.SYS_TABLES T ON T.USER# = M.USER_ID AND T.RECYCLED = 0
  JOIN SYS.SYS_COLUMNS C ON C.USER# = T.USER# AND C.TABLE# = T.ID AND C.FLAGS & 3 = 0 AND TYPE_ID2NAME(C.DATATYPE) NOT IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND (HH.SPARE1 IS NULL OR HH.SPARE1 = 4294967295)
  UNION ALL
  SELECT T.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''),
         C.BYTES, C.PRECISION,  C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, 
         C.DEFAULT_TEXT, C.NUM_DISTINCT, C.LOW_VALUE, C.HIGH_VALUE, HH.NULL_NUM, HH.BUCKET_NUM,
         C.BYTES, DECODE(C.FLAGS & 32, 32, 'C', 'B'), HH.SPARE3, HH.ANALYZE_TIME, C.HISTOGRAM,DECODE(C.FLAGS & 8, 0, 'N', 'Y')
  FROM SYS.DV_ME M JOIN SYS.SYS_TABLES T ON T.USER# = M.USER_ID AND T.RECYCLED = 0
  JOIN SYS.SYS_COLUMNS C ON C.USER# = T.USER# AND C.TABLE# = T.ID AND C.FLAGS & 3 = 0 AND TYPE_ID2NAME(C.DATATYPE) IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND (HH.SPARE1 IS NULL OR HH.SPARE1 = 4294967295)
  UNION ALL
  SELECT V.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''), C.BYTES, C.PRECISION, C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, NULL,NULL::BINARY_INTEGER,NULL,NULL,
  NULL::BINARY_INTEGER,NULL::BINARY_INTEGER,0,NULL::CHAR,NULL::BINARY_INTEGER,NULL::TIMESTAMP,NULL,NULL::CHAR
  FROM SYS.DV_ME ME, SYS.SYS_VIEWS V, SYS.SYS_VIEW_COLS C
  WHERE V.USER# = ME.USER_ID AND C.USER# = ME.USER_ID AND C.VIEW# = V.ID AND TYPE_ID2NAME(C.DATATYPE) NOT IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
  UNION ALL
  SELECT V.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''), C.BYTES, C.PRECISION, C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, NULL,NULL::BINARY_INTEGER,NULL,NULL,
  NULL::BINARY_INTEGER,NULL::BINARY_INTEGER,C.BYTES,NULL::CHAR,NULL::BINARY_INTEGER,NULL::TIMESTAMP,NULL,NULL::CHAR
  FROM SYS.DV_ME ME, SYS.SYS_VIEWS V, SYS.SYS_VIEW_COLS C
  WHERE V.USER# = ME.USER_ID AND C.USER# = ME.USER_ID AND C.VIEW# = V.ID AND TYPE_ID2NAME(C.DATATYPE) IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_TAB_COLUMNS      FOR SYS.MY_TAB_COLUMNS
/
GRANT SELECT ON MY_TAB_COLUMNS TO PUBLIC
/

CREATE OR REPLACE VIEW DB_TAB_COLUMNS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  DATA_TYPE,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE,
  NULLABLE,
  COLUMN_ID,
  DATA_DEFAULT,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  NUM_NULLS,
  NUM_BUCKETS,
  CHAR_LENGTH,
  CHAR_USED,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  HISTOGRAM,
  AUTO_INCREMENT
) 
AS
  SELECT U.NAME, T.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''),
         C.BYTES, C.PRECISION,  C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, 
         C.DEFAULT_TEXT, C.NUM_DISTINCT, C.LOW_VALUE, C.HIGH_VALUE, HH.NULL_NUM, HH.BUCKET_NUM, 
         0, NULL::CHAR, HH.SPARE3, HH.ANALYZE_TIME, C.HISTOGRAM,DECODE(C.FLAGS & 8, 0, 'N', 'Y')
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_COLUMNS C ON C.USER# = T.USER# AND C.TABLE# = T.ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0 AND TYPE_ID2NAME(C.DATATYPE) NOT IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND (HH.SPARE1 IS NULL OR HH.SPARE1 = 4294967295)
    where (U.NAME = user or 
           user = 'SYS' or
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, T.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''),
         C.BYTES, C.PRECISION,  C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, 
         C.DEFAULT_TEXT, C.NUM_DISTINCT, C.LOW_VALUE, C.HIGH_VALUE, HH.NULL_NUM, HH.BUCKET_NUM,
         C.BYTES, DECODE(C.FLAGS & 32, 32, 'C', 'B'), HH.SPARE3, HH.ANALYZE_TIME, C.HISTOGRAM,DECODE(C.FLAGS & 8, 0, 'N', 'Y')
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_COLUMNS C ON C.USER# = T.USER# AND C.TABLE# = T.ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0 AND TYPE_ID2NAME(C.DATATYPE) IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND (HH.SPARE1 IS NULL OR HH.SPARE1 = 4294967295) 
    where (U.NAME = user or 
           user = 'SYS' or
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, V.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''), C.BYTES, C.PRECISION, C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, NULL,NULL::BINARY_INTEGER,NULL,NULL,
  NULL::BINARY_INTEGER,NULL::BINARY_INTEGER,0, NULL::CHAR,NULL::BINARY_INTEGER,NULL::TIMESTAMP,NULL,NULL::CHAR
  FROM SYS.SYS_USERS U, SYS.SYS_VIEWS V, SYS.SYS_VIEW_COLS C 
  WHERE V.USER# = U.ID AND C.USER# = U.ID AND C.VIEW# = V.ID AND TYPE_ID2NAME(C.DATATYPE) NOT IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
    and (U.NAME = user or 
        user = 'SYS' or 
        DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||V.NAME||'"', 'VIEW')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, V.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''), C.BYTES, C.PRECISION, C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, NULL,NULL::BINARY_INTEGER,NULL,NULL,
  NULL::BINARY_INTEGER,NULL::BINARY_INTEGER,C.BYTES, DECODE(C.FLAGS & 32, 32, 'C', 'B'),NULL::BINARY_INTEGER,NULL::TIMESTAMP,NULL,NULL::CHAR
  FROM SYS.SYS_USERS U, SYS.SYS_VIEWS V, SYS.SYS_VIEW_COLS C 
  WHERE V.USER# = U.ID AND C.USER# = U.ID AND C.VIEW# = V.ID AND TYPE_ID2NAME(C.DATATYPE) IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
    and (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||V.NAME||'"', 'VIEW')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_TAB_COLUMNS      FOR SYS.DB_TAB_COLUMNS
/
GRANT SELECT ON DB_TAB_COLUMNS TO PUBLIC
/

CREATE OR REPLACE VIEW ADM_TAB_COLUMNS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  DATA_TYPE,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE,
  NULLABLE,
  COLUMN_ID,
  DATA_DEFAULT,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  NUM_NULLS,
  NUM_BUCKETS,
  CHAR_LENGTH,
  CHAR_USED,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  HISTOGRAM,
  AUTO_INCREMENT
) 
AS
  SELECT U.NAME, T.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''),
         C.BYTES, C.PRECISION,  C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, 
         C.DEFAULT_TEXT, C.NUM_DISTINCT, C.LOW_VALUE, C.HIGH_VALUE, HH.NULL_NUM, HH.BUCKET_NUM, 
         0, NULL::CHAR, HH.SPARE3, HH.ANALYZE_TIME, C.HISTOGRAM,DECODE(C.FLAGS & 8, 0, 'N', 'Y')
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_COLUMNS C ON C.USER# = T.USER# AND C.TABLE# = T.ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0 AND TYPE_ID2NAME(C.DATATYPE) NOT IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND (HH.SPARE1 IS NULL OR HH.SPARE1 = 4294967295)
  UNION ALL
  SELECT U.NAME, T.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''),
         C.BYTES, C.PRECISION,  C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, 
         C.DEFAULT_TEXT, C.NUM_DISTINCT, C.LOW_VALUE, C.HIGH_VALUE, HH.NULL_NUM, HH.BUCKET_NUM,
         C.BYTES, DECODE(C.FLAGS & 32, 32, 'C', 'B'), HH.SPARE3, HH.ANALYZE_TIME, C.HISTOGRAM,DECODE(C.FLAGS & 8, 0, 'N', 'Y')
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_COLUMNS C ON C.USER# = T.USER# AND C.TABLE# = T.ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0 AND TYPE_ID2NAME(C.DATATYPE) IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND (HH.SPARE1 IS NULL OR HH.SPARE1 = 4294967295)
  UNION ALL
  SELECT U.NAME, V.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''), C.BYTES, C.PRECISION, C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, NULL,NULL::BINARY_INTEGER,NULL,NULL,
  NULL::BINARY_INTEGER,NULL::BINARY_INTEGER,0, NULL::CHAR,NULL::BINARY_INTEGER,NULL::TIMESTAMP,NULL,NULL::CHAR
  FROM SYS.SYS_USERS U, SYS.SYS_VIEWS V, SYS.SYS_VIEW_COLS C 
  WHERE V.USER# = U.ID AND C.USER# = U.ID AND C.VIEW# = V.ID AND TYPE_ID2NAME(C.DATATYPE) NOT IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR') AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, V.NAME, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''), C.BYTES, C.PRECISION, C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N'), C.ID, NULL,NULL::BINARY_INTEGER,NULL,NULL,
  NULL::BINARY_INTEGER,NULL::BINARY_INTEGER,C.BYTES, DECODE(C.FLAGS & 32, 32, 'C', 'B'),NULL::BINARY_INTEGER,NULL::TIMESTAMP,NULL,NULL::CHAR
  FROM SYS.SYS_USERS U, SYS.SYS_VIEWS V, SYS.SYS_VIEW_COLS C 
  WHERE V.USER# = U.ID AND C.USER# = U.ID AND C.VIEW# = V.ID AND TYPE_ID2NAME(C.DATATYPE) IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR') AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_TAB_COLUMNS      FOR SYS.ADM_TAB_COLUMNS
/

CREATE OR REPLACE VIEW ADM_DBLINK_TAB_COLUMNS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  DATA_TYPE,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE,
  NULLABLE,
  COLUMN_ID
) 
AS
  SELECT U.NAME, T.NAME, C.NAME, C.DATATYPE,
         C.BYTES, C.PRECISION,  C.SCALE, C.NULLABLE, C.ID
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_COLUMNS C ON C.USER# = T.USER# AND C.TABLE# = T.ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0 AND TYPE_ID2NAME(C.DATATYPE) NOT IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
  UNION ALL
  SELECT U.NAME, T.NAME, C.NAME, C.DATATYPE,
         C.BYTES, C.PRECISION,  C.SCALE, C.NULLABLE, C.ID
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_COLUMNS C ON C.USER# = T.USER# AND C.TABLE# = T.ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0 AND TYPE_ID2NAME(C.DATATYPE) IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_DBLINK_TAB_COLUMNS      FOR SYS.ADM_DBLINK_TAB_COLUMNS
/

CREATE OR REPLACE VIEW DB_DBLINK_TAB_COLUMNS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  DATA_TYPE,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE,
  NULLABLE,
  COLUMN_ID
) 
AS
  SELECT U.NAME, T.NAME, C.NAME, C.DATATYPE,
         C.BYTES, C.PRECISION,  C.SCALE, C.NULLABLE, C.ID
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_COLUMNS C ON C.USER# = T.USER# AND C.TABLE# = T.ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0 AND TYPE_ID2NAME(C.DATATYPE) NOT IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
    where  U.NAME = user or 
           user = 'SYS' or
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE')
  UNION ALL
  SELECT U.NAME, T.NAME, C.NAME, C.DATATYPE,
         C.BYTES, C.PRECISION,  C.SCALE, C.NULLABLE, C.ID
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_COLUMNS C ON C.USER# = T.USER# AND C.TABLE# = T.ID AND T.RECYCLED = 0 AND C.FLAGS & 3 = 0 AND TYPE_ID2NAME(C.DATATYPE) IN ('CHAR','VARCHAR2','NCHAR','NVARCHAR','VARCHAR')
    where  U.NAME = user or 
           user = 'SYS' or
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE')
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_DBLINK_TAB_COLUMNS      FOR SYS.DB_DBLINK_TAB_COLUMNS
/
GRANT SELECT ON DB_DBLINK_TAB_COLUMNS TO PUBLIC
/
--11
CREATE OR REPLACE VIEW DB_VIEWS
(
  OWNER,
  VIEW_NAME,
  VIEW_TYPE,
  COLUMN_COUNT,
  TEXT,
  TEXT_LENGTH,
  CREATED_TIME,
  LAST_DDL_TIME
) 
AS
  SELECT U.NAME, V.NAME, 'NORMAL', V.COLS, V.TEXT, V.TEXT_LENGTH, SCN2DATE(V.ORG_SCN), SCN2DATE(V.CHG_SCN)
  FROM SYS.SYS_USERS U, SYS.SYS_VIEWS V
  WHERE V.USER# = U.ID
    and (U.NAME = user or 
        user = 'SYS' or
        DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||V.NAME||'"', 'VIEW')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT DV.USER_NAME, DV.NAME, 'DYNAMIC', DV.COLUMN_COUNT, NULL, 0, SCN2DATE(0), SCN2DATE(0) FROM SYS.DV_DYNAMIC_VIEWS DV
    WHERE DV.USER_NAME = user or  
        user = 'SYS' or 
        DBE_DIAGNOSE.has_obj_privs(user, 'SYS', '"'||DV.NAME||'"', 'VIEW')
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_VIEWS          FOR SYS.DB_VIEWS 
/
GRANT SELECT ON DB_VIEWS TO PUBLIC
/

CREATE OR REPLACE VIEW ADM_VIEWS
(
  OWNER,
  VIEW_NAME,
  VIEW_TYPE,
  COLUMN_COUNT,
  TEXT,
  TEXT_LENGTH,
  CREATED_TIME,
  LAST_DDL_TIME
) 
AS
  SELECT U.NAME, V.NAME, 'NORMAL', V.COLS, V.TEXT, V.TEXT_LENGTH, SCN2DATE(V.ORG_SCN), SCN2DATE(V.CHG_SCN)
  FROM SYS.SYS_USERS U, SYS.SYS_VIEWS V
  WHERE V.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT DV.USER_NAME, DV.NAME, 'DYNAMIC', DV.COLUMN_COUNT, NULL, 0, SCN2DATE(0), SCN2DATE(0) FROM SYS.DV_DYNAMIC_VIEWS DV
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_VIEWS          FOR SYS.ADM_VIEWS 
/
CREATE OR REPLACE VIEW MY_VIEWS
(
  VIEW_NAME,
  VIEW_TYPE,
  COLUMN_COUNT,
  TEXT,
  TEXT_LENGTH,
  CREATED_TIME,
  LAST_DDL_TIME
) 
AS
  SELECT V.NAME, 'NORMAL', V.COLS, V.TEXT, V.TEXT_LENGTH, SCN2DATE(V.ORG_SCN), SCN2DATE(V.CHG_SCN)
  FROM SYS.DV_ME ME, SYS.SYS_VIEWS V
  WHERE V.USER# = ME.USER_ID
  UNION ALL
  SELECT DV.NAME, 'DYNAMIC', DV.COLUMN_COUNT, NULL, 0, SCN2DATE(0), SCN2DATE(0) 
  FROM SYS.DV_ME ME, SYS.DV_DYNAMIC_VIEWS DV
  WHERE ME.USER_ID = 0
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_VIEWS         FOR SYS.MY_VIEWS 
/
GRANT SELECT ON MY_VIEWS TO PUBLIC
/
CREATE OR REPLACE VIEW DB_VIEW_COLUMNS
(
  OWNER,
  VIEW_NAME,
  COLUMN_ID,
  COLUMN_NAME,
  DATA_TYPE,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE,
  NULLABLE
) 
AS
  SELECT U.NAME, V.NAME, C.ID, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''), C.BYTES, C.PRECISION, C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N')
  FROM SYS.SYS_USERS U, SYS.SYS_VIEWS V, SYS.SYS_VIEW_COLS C 
  WHERE V.USER# = U.ID AND C.USER# = U.ID AND C.VIEW# = V.ID
    and (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||V.NAME||'"', 'VIEW')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT DC.USER_NAME, DC.VIEW_NAME, DC.COLUMN_ID, DC.COLUMN_NAME, DC.DATA_TYPE, DC.DATA_LENGTH, DC.DATA_PRECISION, DC.DATA_SCALE, 'Y' 
  FROM SYS.DV_DYNAMIC_VIEW_COLS DC
  where DC.USER_NAME = user or 
        user = 'SYS' or
        DBE_DIAGNOSE.has_obj_privs(user, 'SYS', '"'||DC.VIEW_NAME||'"', 'VIEW')
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_VIEW_COLUMNS   FOR SYS.DB_VIEW_COLUMNS 
/
GRANT SELECT ON DB_VIEW_COLUMNS TO PUBLIC
/

CREATE OR REPLACE VIEW ADM_VIEW_COLUMNS
(
  OWNER,
  VIEW_NAME,
  COLUMN_ID,
  COLUMN_NAME,
  DATA_TYPE,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE,
  NULLABLE
) 
AS
  SELECT U.NAME, V.NAME, C.ID, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''), C.BYTES, C.PRECISION, C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N')
  FROM SYS.SYS_USERS U, SYS.SYS_VIEWS V, SYS.SYS_VIEW_COLS C 
  WHERE V.USER# = U.ID AND C.USER# = U.ID AND C.VIEW# = V.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT DC.USER_NAME, DC.VIEW_NAME, DC.COLUMN_ID, DC.COLUMN_NAME, DC.DATA_TYPE, DC.DATA_LENGTH, DC.DATA_PRECISION, DC.DATA_SCALE, 'Y' 
  FROM SYS.DV_DYNAMIC_VIEW_COLS DC
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_VIEW_COLUMNS FOR SYS.ADM_VIEW_COLUMNS
/
CREATE OR REPLACE VIEW MY_VIEW_COLUMNS
(
  VIEW_NAME, 
  COLUMN_ID, 
  COLUMN_NAME, 
  DATA_TYPE, 
  DATA_LENGTH, 
  DATA_PRECISION, 
  DATA_SCALE, 
  NULLABLE
)
AS
  SELECT V.NAME, C.ID, C.NAME, TYPE_ID2NAME(C.DATATYPE) || DECODE(C.FLAGS & 1024, 1024, '[]', ''), C.BYTES, C.PRECISION, C.SCALE, DECODE(C.NULLABLE, 1, 'Y', 'N')
  FROM SYS.DV_ME ME, SYS.SYS_VIEWS V, SYS.SYS_VIEW_COLS C
  WHERE V.USER# = ME.USER_ID AND C.USER# = ME.USER_ID AND C.VIEW# = V.ID
  UNION ALL
  SELECT DC.VIEW_NAME, DC.COLUMN_ID, DC.COLUMN_NAME, DC.DATA_TYPE, DC.DATA_LENGTH, DC.DATA_PRECISION, DC.DATA_SCALE, 'Y' 
  FROM SYS.DV_ME ME, SYS.DV_DYNAMIC_VIEW_COLS DC
  WHERE ME.USER_ID = 0 
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_VIEW_COLUMNS  FOR SYS.MY_VIEW_COLUMNS 
/
GRANT SELECT ON MY_VIEW_COLUMNS TO PUBLIC
/
--12
CREATE OR REPLACE VIEW DB_INDEXES
(
  OWNER,
  INDEX_NAME,
  INDEX_TYPE,
  TABLE_NAME,
  TABLESPACE_NAME,
  IS_PRIMARY,
  IS_UNIQUE,
  IS_DUPLICATE,
  PARTITIONED,
  STATUS,
  INI_TRANS,
  MAX_TRANS,
  PCT_FREE,
  COLUMN_COUNT,
  COLUMNS,
  BYTES,
  PAGES,
  EXTENTS,
  BLEVEL,
  LEAF_BLOCKS,
  EMPTY_LEAF_BLOCKS,
  DISTINCT_KEYS,
  AVG_LEAF_BLOCKS_PER_KEY,
  AVG_DATA_BLOCKS_PER_KEY,
  CLUSTERING_FACTOR,
  NUM_ROWS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  SYS_GENERATE,
  CR_MODE,
  IS_REVERSED,
  IS_NOLOGGING
)
AS
  SELECT U.NAME, I.NAME, DECODE(I.TYPE, 0, 'NORMAL', 'NORMAL'), 
  T.NAME, DBE_DIAGNOSE.DBA_SPACE_NAME(I.SPACE#)::VARCHAR(64), DECODE(I.IS_PRIMARY, 1, 'Y', 'N'), DECODE(I.IS_UNIQUE, 1, 'Y', 'N'), DECODE(I.FLAGS & 16, 0, 'N', 'Y'),
  DECODE(I.PARTITIONED, 1, 'Y','N'), DECODE(I.FLAGS & 4, 0, 'VALID', 'INVALID'), I.INITRANS, 255, I.PCTFREE, I.COLS, DBE_DIAGNOSE.DBA_LISTCOLS(U.NAME, '"'||T.NAME||'"', I.COL_LIST),
  DECODE(I.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(0, I.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_INDSIZE(0,U.NAME,'"'||T.NAME||'"','"'||I.NAME||'"')),
  DECODE(I.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(1, I.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_INDSIZE(1,U.NAME,'"'||T.NAME||'"','"'||I.NAME||'"')),
  DECODE(I.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(2, I.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_INDSIZE(2,U.NAME,'"'||T.NAME||'"','"'||I.NAME||'"')),
  I.BLEVEL, I.LEVEL_BLOCKS,I.EMPTY_LEAF_BLOCKS, I.DISTINCT_KEYS, I.AVG_LEAF_BLOCKS_PER_KEY, I.AVG_DATA_BLOCKS_PER_KEY, I.CLUFAC,
  T.NUM_ROWS, I.SAMPLESIZE, I.ANALYZETIME, FLAGS & 1,
  DECODE(I.CR_MODE, 0, 'ROW', 1, 'PAGE', NULL),
  DECODE(I.FLAGS & 64, 0, 'N', 'Y'),
  DECODE(I.FLAGS & 128, 0, 'N', 'Y')
  FROM SYS.SYS_USERS U, SYS.SYS_INDEXES I, SYS.SYS_TABLES T
  WHERE T.USER# = U.ID AND I.USER# = U.ID AND I.TABLE# = T.ID AND T.RECYCLED = 0
    AND (U.NAME = user or  
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_INDEXES        FOR SYS.DB_INDEXES 
/
GRANT SELECT ON DB_INDEXES TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_INDEXES
(
  OWNER,
  INDEX_NAME,
  INDEX_TYPE,
  TABLE_NAME,
  TABLESPACE_NAME,
  IS_PRIMARY,
  IS_UNIQUE,
  IS_DUPLICATE,
  PARTITIONED,
  STATUS,
  INI_TRANS,
  MAX_TRANS,
  PCT_FREE,
  COLUMN_COUNT,
  COLUMNS,
  BYTES,
  PAGES,
  EXTENTS,
  BLEVEL,
  LEAF_BLOCKS,
  EMPTY_LEAF_BLOCKS,
  DISTINCT_KEYS,
  AVG_LEAF_BLOCKS_PER_KEY,
  AVG_DATA_BLOCKS_PER_KEY,
  CLUSTERING_FACTOR,
  NUM_ROWS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  SYS_GENERATE,
  CR_MODE,
  IS_REVERSED,
  IS_NOLOGGING
)
AS
  SELECT U.NAME, I.NAME, DECODE(I.TYPE, 0, 'NORMAL', 'NORMAL'), 
  T.NAME, DBE_DIAGNOSE.DBA_SPACE_NAME(I.SPACE#)::VARCHAR(64), DECODE(I.IS_PRIMARY, 1, 'Y', 'N'), DECODE(I.IS_UNIQUE, 1, 'Y', 'N'), DECODE(I.FLAGS & 16, 0, 'N', 'Y'),
  DECODE(I.PARTITIONED, 1, 'Y','N'), DECODE(I.FLAGS & 4, 0, 'VALID', 'INVALID'), I.INITRANS, 255, I.PCTFREE, I.COLS, DBE_DIAGNOSE.DBA_LISTCOLS(U.NAME, '"'||T.NAME||'"', I.COL_LIST),
  DECODE(I.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(0, I.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_INDSIZE(0,U.NAME,'"'||T.NAME||'"','"'||I.NAME||'"')),
  DECODE(I.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(1, I.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_INDSIZE(1,U.NAME,'"'||T.NAME||'"','"'||I.NAME||'"')),
  DECODE(I.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(2, I.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_INDSIZE(2,U.NAME,'"'||T.NAME||'"','"'||I.NAME||'"')),
  I.BLEVEL, I.LEVEL_BLOCKS,I.EMPTY_LEAF_BLOCKS, I.DISTINCT_KEYS, I.AVG_LEAF_BLOCKS_PER_KEY, I.AVG_DATA_BLOCKS_PER_KEY, I.CLUFAC,
  T.NUM_ROWS, I.SAMPLESIZE, I.ANALYZETIME, FLAGS & 1,
  DECODE(I.CR_MODE, 0, 'ROW', 1, 'PAGE', NULL),
  DECODE(I.FLAGS & 64, 0, 'N', 'Y'),
  DECODE(I.FLAGS & 128, 0, 'N', 'Y')
  FROM SYS.SYS_USERS U, SYS.SYS_INDEXES I, SYS.SYS_TABLES T
  WHERE T.USER# = U.ID AND I.USER# = U.ID AND I.TABLE# = T.ID AND T.RECYCLED = 0 AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_INDEXES        FOR SYS.ADM_INDEXES 
/
CREATE OR REPLACE VIEW MY_INDEXES
(
  INDEX_NAME,
  INDEX_TYPE,
  TABLE_NAME,
  TABLESPACE_NAME,
  IS_PRIMARY,
  IS_UNIQUE,
  IS_DUPLICATE,
  PARTITIONED,
  STATUS,
  INI_TRANS,
  MAX_TRANS,
  PCT_FREE,
  COLUMN_COUNT,
  COLUMNS,
  BYTES,
  PAGES,
  EXTENTS,
  BLEVEL,
  LEAF_BLOCKS,
  EMPTY_LEAF_BLOCKS,
  DISTINCT_KEYS,
  AVG_LEAF_BLOCKS_PER_KEY,
  AVG_DATA_BLOCKS_PER_KEY,
  CLUSTERING_FACTOR,
  NUM_ROWS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  SYS_GENERATE,
  CR_MODE,
  IS_REVERSED,
  IS_NOLOGGING
)
AS
  SELECT I.NAME, DECODE(I.TYPE, 0, 'NORMAL', 'NORMAL'), 
  T.NAME, DBE_DIAGNOSE.DBA_SPACE_NAME(I.SPACE#), DECODE(I.IS_PRIMARY, 1, 'Y', 'N'), DECODE(I.IS_UNIQUE, 1, 'Y', 'N'), DECODE(I.FLAGS & 16, 0, 'N', 'Y'),
  DECODE(I.PARTITIONED,1,'Y','N'), DECODE(I.FLAGS & 4, 0, 'VALID', 'INVALID'), I.INITRANS, 255, I.PCTFREE, I.COLS, DBE_DIAGNOSE.DBA_LISTCOLS(ME.USER_NAME, '"'||T.NAME||'"', I.COL_LIST),
  DECODE(I.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(0, I.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_INDSIZE(0,ME.USER_NAME,'"'||T.NAME||'"','"'||I.NAME||'"')),
  DECODE(I.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(1, I.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_INDSIZE(1,ME.USER_NAME,'"'||T.NAME||'"','"'||I.NAME||'"')),
  DECODE(I.PARTITIONED,0,DBE_DIAGNOSE.DBA_SEGSIZE(2, I.ENTRY),1,DBE_DIAGNOSE.DBA_PARTITIONED_INDSIZE(2,ME.USER_NAME,'"'||T.NAME||'"','"'||I.NAME||'"')),
  I.BLEVEL, I.LEVEL_BLOCKS,I.EMPTY_LEAF_BLOCKS, I.DISTINCT_KEYS, I.AVG_LEAF_BLOCKS_PER_KEY, I.AVG_DATA_BLOCKS_PER_KEY, I.CLUFAC,
  T.NUM_ROWS, I.SAMPLESIZE, I.ANALYZETIME, FLAGS & 1,
  DECODE(I.CR_MODE, 0, 'ROW', 1, 'PAGE', NULL),
  DECODE(I.FLAGS & 64, 0, 'N', 'Y'),
  DECODE(I.FLAGS & 128, 0, 'N', 'Y')
  FROM SYS.DV_ME ME, SYS.SYS_INDEXES I, SYS.SYS_TABLES T
  WHERE I.USER# = ME.USER_ID AND T.USER# = ME.USER_ID AND I.TABLE# = T.ID AND T.RECYCLED = 0
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_INDEXES       FOR SYS.MY_INDEXES 
/
GRANT SELECT ON MY_INDEXES TO PUBLIC
/
--13
CREATE OR REPLACE VIEW DB_OBJECTS
(
  OWNER,
  OBJECT_NAME,
  SUBOBJECT_NAME,
  OBJECT_ID,
  OBJECT_TYPE,
  CREATED,
  LAST_DDL_TIME,
  STATUS,
  TEMPORARY
)
AS
  SELECT U.NAME, T.NAME, NULL AS SUBOBJECT_NAME, T.ID, DECODE(T.RECYCLED, 1, 'RECYCLED TABLE', 'TABLE'), 
  SCN2DATE(T.ORG_SCN), SCN2DATE(T.CHG_SCN), 'VALID', if(T.TYPE = 2 or T.TYPE = 3, 'Y', 'N')
   FROM SYS.SYS_USERS U, SYS.SYS_TABLES T
    WHERE T.USER# = U.ID and 
          T.RECYCLED = 0 AND
          (U.NAME = user or  
           user = 'SYS' or
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, T.NAME, P.NAME AS SUBOBJECT_NAME, P.PART#, 'TABLE PARTITION', 
  SCN2DATE(P.ORG_SCN), SCN2DATE(T.CHG_SCN), 'VALID', if(T.TYPE = 2 or T.TYPE = 3, 'Y', 'N')
   FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_TABLE_PARTS P
    WHERE T.USER# = U.ID AND
          T.RECYCLED = 0 AND    
          P.USER# = U.ID AND 
          P.TABLE# = T.ID and 
          (U.NAME = user or  
           user = 'SYS' or
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, T.NAME, SUBP.NAME AS SUBOBJECT_NAME, SUBP.SUBPART#, 'TABLE SUBPARTITION', 
  SCN2DATE(SUBP.ORG_SCN), SCN2DATE(T.CHG_SCN), 'VALID', if(T.TYPE = 2 or T.TYPE = 3, 'Y', 'N')
   FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_SUB_TABLE_PARTS SUBP
    WHERE T.USER# = U.ID AND
          T.RECYCLED = 0 AND    
          SUBP.USER# = U.ID AND 
          SUBP.TABLE# = T.ID and 
          (U.NAME = user or  
           user = 'SYS' or
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL  
  SELECT U.NAME, I.NAME, NULL AS SUBOBJECT_NAME, I.ID, DECODE(T.RECYCLED, 1, 'RECYCLED INDEX', 'INDEX'), 
  SCN2DATE(I.SEQUENCE#), SCN2DATE(I.SEQUENCE#), DECODE(I.FLAGS & 4, 0, 'VALID', 'INVALID'), if(T.TYPE = 2 or T.TYPE = 3, 'Y', 'N')
   FROM SYS.SYS_USERS U, SYS.SYS_INDEXES I, SYS.SYS_TABLES T
    WHERE I.USER# = U.ID AND 
          T.RECYCLED = 0 AND
          T.USER# = U.ID AND 
          I.TABLE# = T.ID AND 
          (U.NAME = user or  
           user = 'SYS' or
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, V.NAME, NULL AS SUBOBJECT_NAME, V.ID, 'VIEW',
  SCN2DATE(V.ORG_SCN), SCN2DATE(V.CHG_SCN), DECODE(V.FLAGS, 1, 'VALID', 0, 'INVALID', 'UNKNOWN'), 'N'
   FROM SYS.SYS_USERS U, SYS.SYS_VIEWS V
    WHERE V.USER# = U.ID and 
          (U.NAME = user or  
           user = 'SYS' or 
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||V.NAME||'"', 'VIEW')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT DV.USER_NAME, DV.NAME, NULL AS SUBOBJECT_NAME, DV.ID, 'DYNAMIC VIEW', 
  SCN2DATE(0), SCN2DATE(0), 'VALID', 'N'
  FROM SYS.DV_DYNAMIC_VIEWS DV
    WHERE DV.USER_NAME = user or  
          user = 'SYS' or 
          DBE_DIAGNOSE.has_obj_privs(user, 'SYS', '"'||DV.NAME||'"', 'VIEW')
 
  UNION ALL
  SELECT U.NAME, P.NAME, NULL AS SUBOBJECT_NAME, P.OBJ#, 
  CASE WHEN P.TYPE='P' THEN 'PROCEDURE' WHEN P.TYPE='T' THEN 'TRIGGER' WHEN P.TYPE='F' THEN 'FUNCTION' WHEN P.TYPE='S' THEN 'PACKAGE SPEC' WHEN P.TYPE='B' THEN 'PACKAGE BODY' WHEN P.TYPE='Y' THEN 'TYPE SPEC' WHEN P.TYPE='O' THEN 'TYPE BODY' ELSE P.TYPE END,
  SCN2DATE(P.ORG_SCN), SCN2DATE(P.CHG_SCN), DECODE(P.STATUS, 1, 'VALID', 0,'INVALID','UNKNOWN'), 'N'
   FROM SYS.SYS_USERS U, SYS.SYS_PROCS P
    WHERE P.USER# = U.ID and   
          (U.NAME = user or 
           user = 'SYS' or
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||P.NAME||'"', P.TYPE)) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, S.NAME, NULL AS SUBOBJECT_NAME, S.ID, 'SEQUENCE',
  SCN2DATE(S.ORG_SCN), SCN2DATE(S.CHG_SCN), 'VALID', 'N'
   FROM SYS.SYS_USERS U, SYS.SYS_SEQUENCES S
    WHERE S.UID = U.ID and 
          (U.NAME = user or  
           user = 'SYS' or
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||S.NAME||'"', 'SEQUENCE') ) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, Y.SYNONYM_NAME, NULL AS SUBOBJECT_NAME, Y.ID, 'SYNONYM',
    SCN2DATE(Y.ORG_SCN), SCN2DATE(Y.CHG_SCN), DECODE(Y.FLAGS, 1, 'VALID', 0,'INVALID','UNKNOWN'), 'N'
   FROM SYS.SYS_USERS U, SYS.SYS_SYNONYMS Y
    WHERE Y.USER# = U.ID and
          Y.TYPE = 0 and    
         (U.NAME = user or 
          U.NAME = 'PUBLIC' or 
          user = 'SYS' or 
          DBE_DIAGNOSE.has_obj_privs(user, Y.TABLE_OWNER, '"'||Y.TABLE_NAME||'"', 'TABLE')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, Y.SYNONYM_NAME, NULL AS SUBOBJECT_NAME, Y.ID, 'SYNONYM',
    SCN2DATE(Y.ORG_SCN), SCN2DATE(Y.CHG_SCN), DECODE(Y.FLAGS, 1, 'VALID', 0,'INVALID','UNKNOWN'), 'N'
   FROM SYS.SYS_USERS U, SYS.SYS_SYNONYMS Y
    WHERE Y.USER# = U.ID and
          Y.TYPE = 1 and    
         (U.NAME = user or 
          U.NAME = 'PUBLIC' or 
          user = 'SYS' or 
          DBE_DIAGNOSE.has_obj_privs(user, Y.TABLE_OWNER, '"'||Y.TABLE_NAME||'"', 'VIEW')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, Y.SYNONYM_NAME, NULL AS SUBOBJECT_NAME, Y.ID, 'SYNONYM',
    SCN2DATE(Y.ORG_SCN), SCN2DATE(Y.CHG_SCN), DECODE(Y.FLAGS, 1, 'VALID', 0,'INVALID','UNKNOWN'), 'N'
   FROM SYS.SYS_USERS U, SYS.SYS_SYNONYMS Y
    WHERE Y.USER# = U.ID and
          Y.TYPE = 8 and    
         (U.NAME = user or 
          U.NAME = 'PUBLIC' or 
          user = 'SYS' or 
          DBE_DIAGNOSE.has_obj_privs(user, Y.TABLE_OWNER, '"'||Y.SYNONYM_NAME||'"', 'FUNCTION')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
   UNION ALL
   SELECT U.NAME, D.DIRECTORY_NAME, NULL AS SUBOBJECT_NAME, NULL AS OBJECT_ID, 'DIRECTORY', NULL AS CREATED, NULL AS LAST_DDL_TIME, NULL AS STATUS, NULL AS TEMPORARY 
   FROM SYS.SYS_USERS U, SYS.SYS_DIRECTORIES D
   WHERE U.ID = D.USER# and 
        (U.NAME = user or 
         user = 'SYS' or 
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||D.DIRECTORY_NAME||'"', 'DIRECTORY')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, L.NAME, NULL AS SUBOBJECT_NAME, NULL AS OBJECT_ID, 'LIBRARY', SCN2DATE(L.ORG_SCN), SCN2DATE(L.CHG_SCN), NULL AS STATUS, 'N' 
  FROM SYS.SYS_USERS U, SYS.SYS_LIBRARIES L
  WHERE U.ID = L.USER# and 
        (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||L.NAME||'"', 'LIBRARY') ) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_OBJECTS        FOR SYS.DB_OBJECTS 
/
GRANT SELECT ON DB_OBJECTS TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_OBJECTS
(
  OWNER,
  OBJECT_NAME,
  SUBOBJECT_NAME,
  OBJECT_ID,
  OBJECT_TYPE,
  CREATED,
  LAST_DDL_TIME,
  STATUS,
  TEMPORARY
)
AS
  SELECT U.NAME, T.NAME, NULL AS SUBOBJECT_NAME, T.ID, DECODE(T.RECYCLED, 1, 'RECYCLED TABLE', 'TABLE'), 
  SCN2DATE(T.ORG_SCN), SCN2DATE(T.CHG_SCN), 'VALID', if(T.TYPE = 2 or T.TYPE = 3, 'Y', 'N')
   FROM SYS.SYS_USERS U, SYS.SYS_TABLES T
    WHERE T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, T.NAME, P.NAME AS SUBOBJECT_NAME, P.PART#, 'TABLE PARTITION', 
  SCN2DATE(P.ORG_SCN), SCN2DATE(T.CHG_SCN), 'VALID', if(T.TYPE = 2 or T.TYPE = 3, 'Y', 'N')
   FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_TABLE_PARTS P
    WHERE T.USER# = U.ID AND P.USER# = U.ID AND P.TABLE# = T.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, T.NAME, SUBP.NAME AS SUBOBJECT_NAME, SUBP.SUBPART#, 'TABLE SUBPARTITION', 
  SCN2DATE(SUBP.ORG_SCN), SCN2DATE(T.CHG_SCN), 'VALID', if(T.TYPE = 2 or T.TYPE = 3, 'Y', 'N')
   FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_SUB_TABLE_PARTS SUBP
    WHERE T.USER# = U.ID AND SUBP.USER# = U.ID AND SUBP.TABLE# = T.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL 
  SELECT U.NAME, I.NAME, NULL AS SUBOBJECT_NAME, I.ID, DECODE(T.RECYCLED, 1, 'RECYCLED INDEX', 'INDEX'), 
  SCN2DATE(I.SEQUENCE#), SCN2DATE(I.SEQUENCE#), DECODE(I.FLAGS & 4, 0, 'VALID', 'INVALID'), if(T.TYPE = 2 or T.TYPE = 3, 'Y', 'N')
   FROM SYS.SYS_USERS U, SYS.SYS_INDEXES I, SYS.SYS_TABLES T
    WHERE I.USER# = U.ID AND T.USER# = U.ID AND I.TABLE# = T.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, V.NAME, NULL AS SUBOBJECT_NAME, V.ID, 'VIEW',
  SCN2DATE(V.ORG_SCN), SCN2DATE(V.CHG_SCN), DECODE(V.FLAGS, 1, 'VALID', 0, 'INVALID', 'UNKNOWN'), 'N'
   FROM SYS.SYS_USERS U, SYS.SYS_VIEWS V
    WHERE V.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT DV.USER_NAME, DV.NAME, NULL AS SUBOBJECT_NAME, DV.ID, 'DYNAMIC VIEW', 
  SCN2DATE(0), SCN2DATE(0), 'VALID', 'N'
  FROM SYS.DV_DYNAMIC_VIEWS DV
  UNION ALL
  SELECT U.NAME, P.NAME, NULL AS SUBOBJECT_NAME, P.OBJ#, 
  CASE WHEN P.TYPE='P' THEN 'PROCEDURE' WHEN P.TYPE='T' THEN 'TRIGGER' WHEN P.TYPE='F' THEN 'FUNCTION' WHEN P.TYPE='S' THEN 'PACKAGE SPEC' WHEN P.TYPE='B' THEN 'PACKAGE BODY' WHEN P.TYPE='Y' THEN 'TYPE SPEC' WHEN P.TYPE='O' THEN 'TYPE BODY' ELSE P.TYPE END,
  SCN2DATE(P.ORG_SCN), SCN2DATE(P.CHG_SCN), DECODE(P.STATUS, 1, 'VALID', 0,'INVALID','UNKNOWN'), 'N'
   FROM SYS.SYS_USERS U, SYS.SYS_PROCS P
    WHERE P.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, S.NAME, NULL AS SUBOBJECT_NAME, S.ID, 'SEQUENCE',
  SCN2DATE(S.ORG_SCN), SCN2DATE(S.CHG_SCN), 'VALID', 'N'
   FROM SYS.SYS_USERS U, SYS.SYS_SEQUENCES S
    WHERE S.UID = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, Y.SYNONYM_NAME, NULL AS SUBOBJECT_NAME, Y.ID, 'SYNONYM',
    SCN2DATE(Y.ORG_SCN), SCN2DATE(Y.CHG_SCN), DECODE(Y.FLAGS, 1, 'VALID', 0,'INVALID','UNKNOWN'), 'N'
   FROM SYS.SYS_USERS U, SYS.SYS_SYNONYMS Y
    WHERE Y.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
   UNION ALL
   SELECT U.NAME, D.DIRECTORY_NAME, NULL AS SUBOBJECT_NAME, NULL AS OBJECT_ID, 'DIRECTORY', NULL AS CREATED, NULL AS LAST_DDL_TIME, NULL AS STATUS, NULL AS TEMPORARY FROM SYS.SYS_USERS U, SYS.SYS_DIRECTORIES D WHERE U.ID = D.USER# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, L.NAME, NULL AS SUBOBJECT_NAME, NULL AS OBJECT_ID, 'LIBRARY', SCN2DATE(L.ORG_SCN), SCN2DATE(L.CHG_SCN), NULL AS STATUS, 'N' FROM SYS.SYS_USERS U, SYS.SYS_LIBRARIES L WHERE U.ID = L.USER# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM ADM_OBJECTS FOR SYS.ADM_OBJECTS
/

CREATE OR REPLACE VIEW MY_OBJECTS
(
  OBJECT_NAME,
  SUBOBJECT_NAME,
  OBJECT_ID,
  OBJECT_TYPE,
  CREATED,
  LAST_DDL_TIME,
  STATUS,
  TEMPORARY
)
AS
  SELECT T.NAME, NULL AS SUBOBJECT_NAME, T.ID, DECODE(T.RECYCLED, 1, 'RECYCLED TABLE', 'TABLE'), 
  SCN2DATE(T.ORG_SCN), SCN2DATE(T.CHG_SCN), 'VALID', if(T.TYPE = 2 or T.TYPE = 3, 'Y', 'N')
  FROM SYS.DV_ME ME, SYS.SYS_TABLES T
  WHERE T.USER# = ME.USER_ID
  UNION ALL
  SELECT T.NAME, P.NAME AS SUBOBJECT_NAME, P.PART#, 'TABLE PARTITION', 
  SCN2DATE(P.ORG_SCN), SCN2DATE(T.CHG_SCN), 'VALID', if(T.TYPE = 2 or T.TYPE = 3, 'Y', 'N')
   FROM SYS.DV_ME ME, SYS.SYS_TABLES T, SYS.SYS_TABLE_PARTS P
    WHERE T.USER# = ME.USER_ID AND P.USER# = ME.USER_ID AND P.TABLE# = T.ID
  UNION ALL
  SELECT T.NAME, SUBP.NAME AS SUBOBJECT_NAME, SUBP.SUBPART#, 'TABLE SUBPARTITION', 
  SCN2DATE(SUBP.ORG_SCN), SCN2DATE(T.CHG_SCN), 'VALID', if(T.TYPE = 2 or T.TYPE = 3, 'Y', 'N')
   FROM SYS.DV_ME ME, SYS.SYS_TABLES T, SYS.SYS_SUB_TABLE_PARTS SUBP
    WHERE T.USER# = ME.USER_ID AND SUBP.USER# = ME.USER_ID AND SUBP.TABLE# = T.ID	
  UNION ALL  
  SELECT I.NAME, NULL AS SUBOBJECT_NAME, I.ID, DECODE(T.RECYCLED, 1, 'RECYCLED INDEX', 'INDEX'), 
  SCN2DATE(I.SEQUENCE#), SCN2DATE(I.SEQUENCE#), DECODE(I.FLAGS & 4, 0, 'VALID', 'INVALID'), if(T.TYPE = 2 or T.TYPE = 3, 'Y', 'N')
  FROM SYS.DV_ME ME, SYS.SYS_INDEXES I, SYS.SYS_TABLES T
  WHERE I.USER# = ME.USER_ID AND T.USER# = I.USER# AND I.TABLE# = T.ID 
  UNION ALL
  SELECT V.NAME, NULL AS SUBOBJECT_NAME, V.ID, 'VIEW', 
  SCN2DATE(V.ORG_SCN), SCN2DATE(V.CHG_SCN), DECODE(V.FLAGS, 1, 'VALID', 0, 'INVALID', 'UNKNOWN'), 'N'
  FROM SYS.DV_ME ME, SYS.SYS_VIEWS V
  WHERE V.USER# = ME.USER_ID 
  UNION ALL
  SELECT P.NAME, NULL AS SUBOBJECT_NAME, P.OBJ#, 
  CASE WHEN P.TYPE='P' THEN 'PROCEDURE' WHEN P.TYPE='T' THEN 'TRIGGER' WHEN P.TYPE='F' THEN 'FUNCTION' WHEN P.TYPE='S' THEN 'PACKAGE SPEC' WHEN P.TYPE='B' THEN 'PACKAGE BODY' WHEN P.TYPE='Y' THEN 'TYPE SPEC' WHEN P.TYPE='O' THEN 'TYPE BODY' ELSE P.TYPE END,
  SCN2DATE(P.ORG_SCN), SCN2DATE(P.CHG_SCN), DECODE(P.STATUS, 1, 'VALID', 0,'INVALID','UNKNOWN'), 'N'
  FROM SYS.DV_ME ME, SYS.SYS_PROCS P
  WHERE P.USER# = ME.USER_ID
  UNION ALL
  SELECT S.NAME, NULL AS SUBOBJECT_NAME, S.ID, 'SEQUENCE',
  SCN2DATE(S.ORG_SCN), SCN2DATE(S.CHG_SCN), 'VALID', 'N'
  FROM SYS.DV_ME ME, SYS.SYS_SEQUENCES S
  WHERE S.UID = ME.USER_ID
  UNION ALL
  SELECT Y.SYNONYM_NAME, NULL AS SUBOBJECT_NAME, Y.ID, 'SYNONYM',
  SCN2DATE(Y.ORG_SCN), SCN2DATE(Y.CHG_SCN), DECODE(Y.FLAGS, 1, 'VALID', 0,'INVALID','UNKNOWN'), 'N'
  FROM SYS.DV_ME ME, SYS.SYS_SYNONYMS Y
  WHERE Y.USER# = ME.USER_ID
  UNION ALL
  SELECT D.DIRECTORY_NAME, NULL AS SUBOBJECT_NAME, NULL AS OBJECT_ID, 'DIRECTORY', NULL AS CREATED, NULL AS LAST_DDL_TIME, NULL AS STATUS, NULL AS TEMPORARY FROM SYS.DV_ME ME, SYS.SYS_DIRECTORIES D WHERE ME.USER_ID = D.USER#
  UNION ALL
  SELECT L.NAME, NULL AS SUBOBJECT_NAME, NULL AS OBJECT_ID, 'LIBRARY', SCN2DATE(L.ORG_SCN), SCN2DATE(L.CHG_SCN), NULL AS STATUS, 'N' FROM SYS.DV_ME ME, SYS.SYS_LIBRARIES L WHERE ME.USER_ID = L.USER#
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_OBJECTS       FOR SYS.MY_OBJECTS 
/
GRANT SELECT ON MY_OBJECTS TO PUBLIC
/
--14
CREATE OR REPLACE VIEW ADM_TABLESPACES 
(
  TABLESPACE_NAME,
  PAGE_SIZE,
  EXTENT_PAGES,
  DATAFILE_COUNT,
  TOTAL_SIZE,
  USED_SIZE,
  NORMAL_TOTAL_SIZE,
  NORMAL_USED_SIZE,
  COMPRESS_TOTAL_SIZE,
  COMPRESS_USED_SIZE,
  STATUS,
  IN_MEMORY,
  CONTENTS,
  LOGGING,
  BIGFILE,
  ENCRYPT
)
AS
  SELECT TS.NAME, DBE_DIAGNOSE.DBA_SPCSIZE(TS.ID, 'PAGE'), TS.EXTENT_SIZE, TS.FILE_COUNT, 
  DBE_DIAGNOSE.DBA_SPCSIZE(TS.ID, 'TOTAL'), DBE_DIAGNOSE.DBA_SPCSIZE(TS.ID, 'USED'), 
  DBE_DIAGNOSE.DBA_SPCSIZE(TS.ID, 'NORMAL_TOTAL'), DBE_DIAGNOSE.DBA_SPCSIZE(TS.ID, 'NORMAL_USED'),
  DBE_DIAGNOSE.DBA_SPCSIZE(TS.ID, 'COMPRESS_TOTAL'), DBE_DIAGNOSE.DBA_SPCSIZE(TS.ID, 'COMPRESS_USED'),
  TS.STATUS, TS.IN_MEMORY, 
  DECODE(TS.TEMPORARY, 'TRUE', 'TEMPORARY', 'PERMANENT'),
  DECODE(TS.TEMPORARY, 'TRUE', 'N', 'Y'), 'N',
  DECODE(TS.ENCRYPT, 'TRUE', 'Y', 'N')
  FROM SYS.DV_TABLESPACES TS
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_TABLESPACES    FOR SYS.ADM_TABLESPACES 
/
CREATE OR REPLACE VIEW MY_FREE_TABLESPACES
(
  TABLESPACE_NAME,
  PAGE_SIZE,
  EXTENT_PAGES,
  DATAFILE_COUNT,
  TOTAL_SIZE,
  USED_SIZE,
  STATUS
) 
AS
  SELECT TABLESPACE_NAME, PAGE_SIZE, EXTENT_PAGES, DATAFILE_COUNT, TOTAL_SIZE, USED_SIZE, STATUS FROM SYS.ADM_TABLESPACES
/
CREATE OR REPLACE PUBLIC SYNONYM MY_FREE_TABLESPACES FOR SYS.MY_FREE_TABLESPACES 
/
GRANT SELECT ON MY_FREE_TABLESPACES TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_FREE_SPACE
(
  TABLESPACE_NAME,
  FILE_ID,
  BLOCK_ID,
  BYTES,
  BLOCKS,
  RELATIVE_FNO
)
AS
  SELECT * FROM SYS.DV_FREE_SPACE
/
CREATE OR REPLACE PUBLIC SYNONYM ADM_FREE_SPACE FOR SYS.ADM_FREE_SPACE
/
CREATE OR REPLACE VIEW MY_FREE_SPACE
(
  TABLESPACE_NAME,
  FILE_ID,
  BLOCK_ID,
  BYTES,
  BLOCKS,
  RELATIVE_FNO
)
AS
  SELECT
  TABLESPACE_NAME,
  FILE_ID,
  BLOCK_ID,
  BYTES,
  BLOCKS,
  RELATIVE_FNO
  FROM SYS.DV_FREE_SPACE
/
CREATE OR REPLACE PUBLIC SYNONYM MY_FREE_SPACE FOR SYS.MY_FREE_SPACE
/
GRANT SELECT ON MY_FREE_SPACE TO PUBLIC
/
--15
CREATE OR REPLACE VIEW MY_SYNONYMS
(
  SYNONYM_NAME,
  TABLE_OWNER,
  TABLE_NAME
)
AS
  SELECT  S.SYNONYM_NAME, S.TABLE_OWNER, S.TABLE_NAME
  FROM SYS.DV_ME ME  INNER JOIN  SYS.SYS_SYNONYMS S ON ME.USER_ID = S.USER# 
  
/
COMMENT ON COLUMN SYS.MY_SYNONYMS.SYNONYM_NAME IS 'Name of the synonym' 
/
COMMENT ON COLUMN SYS.MY_SYNONYMS.TABLE_OWNER IS 'Owner of the object referenced by the synonym'
/
COMMENT ON COLUMN SYS.MY_SYNONYMS.TABLE_NAME IS 'Name of the object referenced by the synonym'
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_SYNONYMS      FOR SYS.MY_SYNONYMS 
/
GRANT SELECT ON MY_SYNONYMS TO PUBLIC
/

CREATE OR REPLACE VIEW SYS.ADM_SYNONYMS 
(
  OWNER,
  SYNONYM_NAME,
  TABLE_OWNER,
  TABLE_NAME
)
AS
  SELECT U.NAME, S.SYNONYM_NAME, S.TABLE_OWNER, S.TABLE_NAME
  FROM SYS.SYS_USERS U  INNER JOIN  SYS.SYS_SYNONYMS S ON U.ID = S.USER#
      WHERE DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID) OR U.NAME = 'PUBLIC'
/
COMMENT ON COLUMN SYS.ADM_SYNONYMS.OWNER IS 'Username of the owner of the synonym'
/
COMMENT ON COLUMN SYS.ADM_SYNONYMS.SYNONYM_NAME IS 'Name of the synonym'
/
COMMENT ON COLUMN SYS.ADM_SYNONYMS.TABLE_OWNER IS 'Owner of the object referenced by the synonym'
/
COMMENT ON COLUMN SYS.ADM_SYNONYMS.TABLE_NAME IS 'Name of the object referenced by the synonym'
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_SYNONYMS       FOR SYS.ADM_SYNONYMS 
/
CREATE OR REPLACE VIEW SYS.DB_SYNONYMS 
(
  OWNER,
  SYNONYM_NAME,
  TABLE_OWNER,
  TABLE_NAME
)
AS
  SELECT U.NAME, S.SYNONYM_NAME, S.TABLE_OWNER, S.TABLE_NAME
  FROM SYS.SYS_USERS U  INNER JOIN  SYS.SYS_SYNONYMS S ON U.ID = S.USER#
    where S.TYPE = 0 and
          (U.NAME = user or 
           user = 'SYS' or 
           U.NAME = 'PUBLIC' or  
           (DBE_DIAGNOSE.has_obj_privs(user, S.TABLE_OWNER, '"'||S.TABLE_NAME||'"', 'TABLE') AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)))
  UNION ALL  
  SELECT U.NAME, S.SYNONYM_NAME, S.TABLE_OWNER, S.TABLE_NAME
  FROM SYS.SYS_USERS U  INNER JOIN  SYS.SYS_SYNONYMS S ON U.ID = S.USER#
    where S.TYPE = 1 and
          (U.NAME = user or 
           user = 'SYS' or 
           U.NAME = 'PUBLIC' or
           (DBE_DIAGNOSE.has_obj_privs(user, S.TABLE_OWNER, '"'||S.TABLE_NAME||'"', 'VIEW') AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)))
  UNION ALL
  SELECT U.NAME, S.SYNONYM_NAME, S.TABLE_OWNER, S.TABLE_NAME
  FROM SYS.SYS_USERS U  INNER JOIN  SYS.SYS_SYNONYMS S ON U.ID = S.USER#
    where S.TYPE = 8 and
          (U.NAME = user or 
           user = 'SYS' or 
           U.NAME = 'PUBLIC' or
           (DBE_DIAGNOSE.has_obj_privs(user, S.TABLE_OWNER, '"'||S.SYNONYM_NAME||'"', 'FUNCTION') AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)))
  UNION ALL
  SELECT U.NAME, S.SYNONYM_NAME, S.TABLE_OWNER, S.TABLE_NAME
  FROM SYS.SYS_USERS U  INNER JOIN  SYS.SYS_SYNONYMS S ON U.ID = S.USER#
    where S.TYPE = 3 and
          (U.NAME = user or 
           user = 'SYS' or 
           U.NAME = 'PUBLIC' or
           (DBE_DIAGNOSE.has_obj_privs(user, S.TABLE_OWNER, '"'||S.SYNONYM_NAME||'"', 'PROCEDURE') AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)))
  UNION ALL
  SELECT U.NAME, S.SYNONYM_NAME, S.TABLE_OWNER, S.TABLE_NAME
  FROM SYS.SYS_USERS U  INNER JOIN  SYS.SYS_SYNONYMS S ON U.ID = S.USER#
    where S.TYPE = 16 and
          (U.NAME = user or 
           user = 'SYS' or 
           U.NAME = 'PUBLIC' or
           (DBE_DIAGNOSE.has_obj_privs(user, S.TABLE_OWNER, '"'||S.SYNONYM_NAME||'"', 'PACKAGE') AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)))
  UNION ALL
  SELECT U.NAME, S.SYNONYM_NAME, S.TABLE_OWNER, S.TABLE_NAME
  FROM SYS.SYS_USERS U  INNER JOIN  SYS.SYS_SYNONYMS S ON U.ID = S.USER#
    where S.TYPE = 19 and
          (U.NAME = user or 
           user = 'SYS' or 
           U.NAME = 'PUBLIC' or
           (DBE_DIAGNOSE.has_obj_privs(user, S.TABLE_OWNER, '"'||S.SYNONYM_NAME||'"', 'TYPE') AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)))
  UNION ALL
  SELECT U.NAME, S.SYNONYM_NAME, S.TABLE_OWNER, S.TABLE_NAME
  FROM SYS.SYS_USERS U  INNER JOIN  SYS.SYS_SYNONYMS S ON U.ID = S.USER#
    where S.TYPE = 30 and
          (U.NAME = user or 
           user = 'SYS' or 
           U.NAME = 'PUBLIC' or
           (DBE_DIAGNOSE.has_obj_privs(user, S.TABLE_OWNER, '"'||S.SYNONYM_NAME||'"', 'SYSPACKAGE') AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)))
/ 
CREATE OR REPLACE PUBLIC SYNONYM  DB_SYNONYMS       FOR SYS.DB_SYNONYMS 
/
GRANT SELECT ON DB_SYNONYMS TO PUBLIC
/
--16
CREATE OR REPLACE VIEW MY_TAB_COMMENTS 
(
  TABLE_NAME,
  TABLE_TYPE,
  COMMENTS
)
AS
  SELECT  T.NAME, 'TABLE', C.TEXT
  FROM SYS.SYS_TABLES T INNER JOIN SYS.DV_ME ME ON ME.USER_ID = T.USER# AND T.RECYCLED = 0 INNER JOIN SYS.SYS_COMMENTS C  ON  T.USER# = C.USER# AND T.ID = C.TABLE# AND C.COLUMN# IS NULL
  UNION ALL
  SELECT  V.NAME, 'VIEW', C.TEXT
  FROM SYS.SYS_VIEWS V INNER JOIN SYS.DV_ME ME ON ME.USER_ID = V.USER# INNER JOIN SYS.SYS_COMMENTS C  ON  V.USER# = C.USER# AND V.ID = C.TABLE# AND C.COLUMN# IS NULL
/
COMMENT ON COLUMN SYS.MY_TAB_COMMENTS.TABLE_NAME IS 'Name of the object' 
/
COMMENT ON COLUMN SYS.MY_TAB_COMMENTS.TABLE_TYPE IS 'Type of the object:  "TABLE" or "VIEW"'
/
COMMENT ON COLUMN SYS.MY_TAB_COMMENTS.COMMENTS IS 'Comment on the object'
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_TAB_COMMENTS  FOR SYS.MY_TAB_COMMENTS 
/
GRANT SELECT ON MY_TAB_COMMENTS TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_TAB_COMMENTS 
(
  OWNER,
  TABLE_NAME,
  TABLE_TYPE,
  COMMENTS
)
AS
  SELECT  U.NAME, T.NAME, 'TABLE', C.TEXT
  FROM SYS.SYS_TABLES T INNER JOIN  SYS.SYS_USERS U ON U.ID = T.USER# AND T.RECYCLED = 0 AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID) INNER JOIN SYS.SYS_COMMENTS C  ON  T.USER# = C.USER# AND T.ID = C.TABLE# AND C.COLUMN# IS NULL
  UNION ALL
  SELECT  U.NAME, V.NAME, 'VIEW', C.TEXT
  FROM SYS.SYS_VIEWS V INNER JOIN SYS.SYS_USERS U ON U.ID = V.USER# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID) INNER JOIN SYS.SYS_COMMENTS C  ON  V.USER# = C.USER# AND V.ID = C.TABLE# AND C.COLUMN# IS NULL
/ 
COMMENT ON COLUMN SYS.ADM_TAB_COMMENTS.OWNER IS 'Owner of the object'
/
COMMENT ON COLUMN SYS.ADM_TAB_COMMENTS.TABLE_NAME IS 'Name of the object'
/
COMMENT ON COLUMN SYS.ADM_TAB_COMMENTS.TABLE_TYPE IS 'Type of the object'
/
COMMENT ON COLUMN SYS.ADM_TAB_COMMENTS.COMMENTS IS 'Comment on the object'
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_TAB_COMMENTS   FOR SYS.ADM_TAB_COMMENTS 
/
CREATE OR REPLACE VIEW DB_TAB_COMMENTS 
(
  OWNER,
  TABLE_NAME,
  TABLE_TYPE,
  COMMENTS
)
AS
  SELECT  U.NAME, T.NAME, 'TABLE', C.TEXT
  FROM SYS.SYS_TABLES T INNER JOIN  SYS.SYS_USERS U ON U.ID = T.USER# AND T.RECYCLED = 0 AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID) INNER JOIN SYS.SYS_COMMENTS C  ON  T.USER# = C.USER# AND T.ID = C.TABLE# AND C.COLUMN# IS NULL
    where (U.NAME = user or 
           user = 'SYS' or
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
  UNION ALL
  SELECT  U.NAME, V.NAME, 'VIEW', C.TEXT
  FROM SYS.SYS_VIEWS V INNER JOIN SYS.SYS_USERS U ON U.ID = V.USER# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID) INNER JOIN SYS.SYS_COMMENTS C  ON  V.USER# = C.USER# AND V.ID = C.TABLE# AND C.COLUMN# IS NULL
    where (U.NAME = user or 
           user = 'SYS' or
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||V.NAME||'"', 'VIEW'))
/ 
COMMENT ON COLUMN SYS.DB_TAB_COMMENTS.OWNER IS 'Owner of the object'
/
COMMENT ON COLUMN SYS.DB_TAB_COMMENTS.TABLE_NAME IS 'Name of the object'
/
COMMENT ON COLUMN SYS.DB_TAB_COMMENTS.TABLE_TYPE IS 'Type of the object'
/
COMMENT ON COLUMN SYS.DB_TAB_COMMENTS.COMMENTS IS 'Comment on the object'
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_TAB_COMMENTS  FOR SYS.DB_TAB_COMMENTS 
/
GRANT SELECT ON DB_TAB_COMMENTS TO PUBLIC
/

CREATE OR REPLACE VIEW MY_COL_COMMENTS 
(
  TABLE_NAME,
  COLUMN_NAME,
  COMMENTS
)
AS
  SELECT  T.NAME, C.NAME, CO.TEXT
  FROM  SYS.DV_ME ME, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.SYS_COMMENTS CO WHERE  ME.USER_ID = T.USER# AND T.RECYCLED = 0 AND T.USER# = C.USER# AND T.ID = C.TABLE# AND C.USER# = CO.USER# AND C.TABLE# = CO.TABLE# AND C.ID = CO.COLUMN#
  UNION ALL
  SELECT V.NAME, V_C.NAME, CO.TEXT
  FROM SYS.DV_ME ME, SYS.SYS_VIEWS V, SYS.SYS_VIEW_COLS V_C, SYS.SYS_COMMENTS CO WHERE  ME.USER_ID = V.USER# AND V.USER# = V_C.USER# AND V.ID = V_C.VIEW# AND V_C.USER# = CO.USER# AND V_C.VIEW# = CO.TABLE# AND V_C.ID = CO.COLUMN#
/
COMMENT ON COLUMN SYS.MY_COL_COMMENTS.TABLE_NAME IS 'Name of the object'
/
COMMENT ON COLUMN SYS.MY_COL_COMMENTS.COLUMN_NAME IS 'Name of the column'
/
COMMENT ON COLUMN SYS.MY_COL_COMMENTS.COMMENTS IS 'Comment on the object'
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_COL_COMMENTS  FOR SYS.MY_COL_COMMENTS 
/
GRANT SELECT ON MY_COL_COMMENTS TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_COL_COMMENTS 
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  COMMENTS
)
AS
  SELECT U.NAME, T.NAME, C.NAME, CO.TEXT
  FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.SYS_COMMENTS CO WHERE U.ID = T.USER# AND T.RECYCLED = 0 AND T.USER# = C.USER# AND T.ID = C.TABLE# AND C.USER# = CO.USER# AND C.TABLE# = CO.TABLE# AND C.ID = CO.COLUMN# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, V.NAME, V_C.NAME, CO.TEXT
  FROM SYS.SYS_USERS U, SYS.SYS_VIEWS V, SYS.SYS_VIEW_COLS V_C, SYS.SYS_COMMENTS CO WHERE U.ID = V.USER# AND V.USER# = V_C.USER# AND V.ID = V_C.VIEW#  AND V_C.USER# = CO.USER# AND V_C.VIEW# = CO.TABLE# AND V_C.ID = CO.COLUMN# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/ 
CREATE OR REPLACE PUBLIC SYNONYM  ADM_COL_COMMENTS   FOR SYS.ADM_COL_COMMENTS 
/
CREATE OR REPLACE VIEW DB_COL_COMMENTS 
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  COMMENTS
)
AS
  SELECT U.NAME, T.NAME, C.NAME, CO.TEXT
  FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.SYS_COMMENTS CO WHERE U.ID = T.USER# AND T.RECYCLED = 0 AND T.USER# = C.USER# AND T.ID = C.TABLE# AND C.USER# = CO.USER# AND C.TABLE# = CO.TABLE# AND C.ID = CO.COLUMN#
  AND (U.NAME = user or 
       user = 'SYS' or 
       DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, V.NAME, V_C.NAME, CO.TEXT
  FROM SYS.SYS_USERS U, SYS.SYS_VIEWS V, SYS.SYS_VIEW_COLS V_C, SYS.SYS_COMMENTS CO WHERE U.ID = V.USER# AND V.USER# = V_C.USER# AND V.ID = V_C.VIEW#  AND V_C.USER# = CO.USER# AND V_C.VIEW# = CO.TABLE# AND V_C.ID = CO.COLUMN#
    AND (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||V.NAME||'"', 'VIEW')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_COL_COMMENTS  FOR SYS.DB_COL_COMMENTS 
/
GRANT SELECT ON DB_COL_COMMENTS TO PUBLIC
/
--17
CREATE OR REPLACE VIEW DB_USERS
(
  USER_ID,
  USERNAME,
  CREATED,
  CRYPTOPERIOD
)
AS
  SELECT U.ID, U.NAME, U.CTIME, decode(U.ASTATUS, 
  1 ,cast(NUMTODSINTERVAL(0, 'DAY') as varchar(64)),
  5 ,cast(NUMTODSINTERVAL(0, 'DAY') as varchar(64)),
  9 ,cast(NUMTODSINTERVAL(0, 'DAY') as varchar(64)),
  17,cast(NUMTODSINTERVAL(0, 'DAY') as varchar(64)),
  21,cast(NUMTODSINTERVAL(0, 'DAY') as varchar(64)),
  25,cast(NUMTODSINTERVAL(0, 'DAY') as varchar(64)),
  cast(DECODE(P.THRESHOLD, 0, 'UNLIMITED', U.PTIME + NUMTODSINTERVAL(P.THRESHOLD / 86400.0, 'DAY') - CURRENT_TIMESTAMP()) as varchar(64)))
  FROM SYS.SYS_USERS U JOIN SYS.SYS_PROFILE P ON U.PROFILE# = P.PROFILE# AND P.RESOURCE# = 1 AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_USERS          FOR SYS.DB_USERS 
/
CREATE OR REPLACE VIEW MY_SOURCE 
(NAME, TYPE, LINE, TEXT)
AS
SELECT 
	P.NAME, DECODE(P.TYPE, 'T', 'TRIGGER', 'P', 'PROCEDURE', 'F', 'FUNCTION', 'S', 'PACKAGE SPEC', 'B', 'PACKAGE BODY', 'Y', 'TYPE SPEC', 'O', 'TYPE BODY', 'UNDEFINED'),
	NULL::NUMBER, P.SOURCE
FROM SYS.DV_ME ME, SYS.SYS_PROCS P
WHERE  P.USER# = ME.USER_ID
/

CREATE OR REPLACE VIEW ADM_SOURCE 
(OWNER, NAME, TYPE, LINE, TEXT)
AS
SELECT 
	U.NAME, P.NAME, DECODE(P.TYPE, 'T', 'TRIGGER', 'P', 'PROCEDURE', 'F', 'FUNCTION','S', 'PACKAGE SPEC', 'B', 'PACKAGE BODY', 'Y', 'TYPE SPEC', 'O', 'TYPE BODY', 'UNDEFINED'),
	NULL::NUMBER, P.SOURCE
FROM SYS.SYS_USERS U, SYS.SYS_PROCS P
WHERE  P.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_SOURCE         FOR SYS.ADM_SOURCE 
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_SOURCE        FOR SYS.MY_SOURCE 
/
GRANT SELECT ON MY_SOURCE TO PUBLIC
/
CREATE OR REPLACE VIEW DB_SOURCE 
(OWNER, NAME, TYPE, LINE, TEXT)
AS
SELECT 
	U.NAME, P.NAME, DECODE(P.TYPE, 'T', 'TRIGGER', 'P', 'PROCEDURE', 'F', 'FUNCTION','S', 'PACKAGE SPEC', 'B', 'PACKAGE BODY', 'Y', 'TYPE SPEC', 'O', 'TYPE BODY', 'UNDEFINED'),
	NULL::NUMBER, P.SOURCE
FROM SYS.SYS_USERS U, SYS.SYS_PROCS P
WHERE  P.USER# = U.ID and   
       (U.NAME = user or 
        user = 'SYS' or
        DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||P.NAME||'"', P.TYPE)) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_SOURCE         FOR SYS.DB_SOURCE 
/
GRANT SELECT ON DB_SOURCE TO PUBLIC
/
--18
CREATE OR REPLACE VIEW ADM_PROFILES
(
  PROFILE,
  RESOURCE_NAME,
  RESOURCE_TYPE,
  THRESHOLD
)
AS
  SELECT P.NAME, M.NAME, DECODE(M.TYPE#, 0, 'KERNEL', 1, 'PASSWORD'), 
  DECODE(P.THRESHOLD, 0, 'UNLIMITED', DECODE(P.RESOURCE#, 1, CAST(P.THRESHOLD/86400 AS  NUMBER(16,6)), 2, CAST(P.THRESHOLD/86400 AS  NUMBER(16,6)), 4, CAST(P.THRESHOLD/86400 AS  NUMBER(16,6)), 5, CAST(P.THRESHOLD/86400 AS  NUMBER(16,6)), P.THRESHOLD))
  FROM SYS.SYS_PROFILE P, SYS.DV_RESOURCE_MAP M WHERE P.RESOURCE# = M.RESOURCE# ORDER BY P.NAME, M.TYPE# 
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_PROFILES       FOR SYS.ADM_PROFILES 
/

CREATE OR REPLACE VIEW DB_PROFILES
(
  OWNER,
  PROFILE,
  RESOURCE_NAME,
  RESOURCE_TYPE,
  THRESHOLD
)
AS
  SELECT U.NAME, P.NAME, M.NAME, DECODE(M.TYPE#, 0, 'KERNEL', 1, 'PASSWORD'), 
  DECODE(P.THRESHOLD, 0, 'UNLIMITED', DECODE(P.RESOURCE#, 1, CAST(P.THRESHOLD/86400 AS  NUMBER(16,6)), 2, CAST(P.THRESHOLD/86400 AS  NUMBER(16,6)), 4, CAST(P.THRESHOLD/86400 AS  NUMBER(16,6)), 5, CAST(P.THRESHOLD/86400 AS  NUMBER(16,6)), P.THRESHOLD))
  FROM SYS.SYS_USERS U, SYS.SYS_PROFILE P, SYS.DV_RESOURCE_MAP M 
  WHERE U.PROFILE# = P.PROFILE# AND P.RESOURCE# = M.RESOURCE# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID) ORDER BY P.NAME, M.TYPE#
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_PROFILES       FOR SYS.DB_PROFILES 
/
GRANT SELECT ON DB_PROFILES TO PUBLIC
/
--19
CREATE OR REPLACE VIEW SYS.DB_USER_SYS_PRIVS
(
  USERNAME,
  PRIVILEGE,
  ADMIN_OPTION
)
AS
  SELECT U.NAME,
  DECODE(P.PRIVILEGE,
  1, 'ALTER ANY INDEX',
  2, 'ALTER ANY MATERIALIZED VIEW',
  3, 'ALTER ANY PROCEDURE',
  4, 'ALTER ANY ROLE',
  5, 'ALTER ANY SEQUENCE',
  6, 'ALTER ANY TABLE',
  7, 'ALTER ANY TRIGGER',
  8, 'ALTER DATABASE',
  9, 'ALTER PROFILE',
  10, 'ALTER SESSION',
  11, 'ALTER SYSTEM',
  12, 'ALTER TABLESPACE',
  13, 'ALTER USER',
  14, 'CREATE ANY INDEX',
  15, 'CREATE ANY MATERIALIZED VIEW',
  16, 'CREATE ANY PROCEDURE',
  17, 'CREATE ANY SEQUENCE',
  18, 'CREATE ANY SYNONYM',
  19, 'CREATE ANY TABLE',
  20, 'CREATE ANY TRIGGER',
  21, 'CREATE ANY VIEW',
  22, 'CREATE DATABASE',
  23, 'CREATE MATERIALIZED VIEW',
  24, 'CREATE NODE',
  25, 'CREATE PROCEDURE',
  26, 'CREATE PROFILE',
  27, 'CREATE PUBLIC SYNONYM',
  28, 'CREATE ROLE',
  29, 'CREATE SEQUENCE',
  30, 'CREATE SESSION',
  31, 'CREATE SYNONYM',
  32, 'CREATE TABLE',
  33, 'CREATE TABLESPACE',
  34, 'CREATE TRIGGER',
  35, 'CREATE USER',
  36, 'CREATE VIEW',
  38, 'DROP ANY INDEX',
  39, 'DROP ANY MATERIALIZED VIEW',
  40, 'DROP ANY PROCEDURE',
  41, 'DROP ANY ROLE',
  42, 'DROP ANY SEQUENCE',
  43, 'DROP ANY SYNONYM',
  44, 'DROP ANY TABLE',
  45, 'DROP ANY TRIGGER',
  46, 'DROP ANY VIEW',
  47, 'DROP PROFILE',
  48, 'DROP PUBLIC SYNONYM',
  49, 'DROP TABLESPACE',
  50, 'DROP USER',
  51, 'FLASHBACK ANY TABLE',
  52, 'FLASHBACK ARCHIVE ADMINISTER',
  53, 'GLOBAL QUERY REWRITE',
  54, 'GRANT ANY OBJECT PRIVILEGE',
  55, 'GRANT ANY PRIVILEGE',
  56, 'GRANT ANY ROLE',
  57, 'LOCK ANY TABLE',
  58, 'MANAGE TABLESPACE',
  59, 'ON COMMIT REFRESH',
  60, 'PURGE DBA_RECYCLEBIN',
  61, 'READ ANY TABLE',
  62, 'SELECT ANY SEQUENCE',
  63, 'SELECT ANY TABLE',
  64, 'UNLIMITED TABLESPACE',
  65, 'UNDER ANY VIEW',
  66, 'COMMENT ANY TABLE',
  67, 'UPDATE ANY TABLE',
  68, 'INSERT ANY TABLE',
  69, 'DELETE ANY TABLE',
  70, 'EXECUTE ANY PROCEDURE',
  71, 'SYSBACKUP',
  72, 'SYSDBA',
  73, 'SYSOPER',
  74, 'ANALYZE ANY',
  75, 'DROP NODE',
  76, 'ALTER NODE',
  78, 'CREATE ANY DIRECTORY',
  79, 'DROP ANY DIRECTORY',
  81, 'CREATE ANY SQL MAP',
  82, 'DROP ANY SQL MAP',
  83, 'CREATE ANY TYPE',
  84, 'CREATE TYPE',
  85, 'DROP ANY TYPE',
  86, 'EXECUTE ANY TYPE',
  87, 'CREATE CTRLFILE',
  88, 'CREATE LIBRARY',
  89, 'EXEMPT REDACTION POLICY',
  90, 'CREATE ANY LIBRARY',
  91, 'DROP ANY LIBRARY',
  92, 'EXECUTE ANY LIBRARY', 
  93, 'EXEMPT ACCESS POLICY',
  94, 'INHERIT ANY PRIVILEGES',
  95, 'CREATE TENANT',
  96, 'ALTER TENANT',
  97, 'DROP TENANT',
  98, 'SELECT ANY DICTIONARY',
  99, 'FORCE ANY TRANSACTION',
  100, 'CREATE DATABASE LINK',
  101, 'ALTER DATABASE LINK',
  102, 'DROP DATABASE LINK',
  103, 'USE ANY TABLESPACE',
  'UNKNOWN'),
  DECODE(P.ADMIN_OPTION, 0, 'NO', 'YES')
  FROM SYS.SYS_USERS U INNER JOIN SYS.SYS_PRIVS P ON U.ID = P.GRANTEE_ID AND P.GRANTEE_TYPE = 0 AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_USER_SYS_PRIVS FOR SYS.DB_USER_SYS_PRIVS
/
CREATE OR REPLACE VIEW SYS.ADM_SYS_PRIVS
(
  GRANTEE,
  PRIVILEGE,
  ADMIN_OPTION
)
AS
  SELECT * FROM SYS.DB_USER_SYS_PRIVS
  UNION ALL
  SELECT R.NAME,
  DECODE(P.PRIVILEGE,
  1, 'ALTER ANY INDEX',
  2, 'ALTER ANY MATERIALIZED VIEW',
  3, 'ALTER ANY PROCEDURE',
  4, 'ALTER ANY ROLE',
  5, 'ALTER ANY SEQUENCE',
  6, 'ALTER ANY TABLE',
  7, 'ALTER ANY TRIGGER',
  8, 'ALTER DATABASE',
  9, 'ALTER PROFILE',
  10, 'ALTER SESSION',
  11, 'ALTER SYSTEM',
  12, 'ALTER TABLESPACE',
  13, 'ALTER USER',
  14, 'CREATE ANY INDEX',
  15, 'CREATE ANY MATERIALIZED VIEW',
  16, 'CREATE ANY PROCEDURE',
  17, 'CREATE ANY SEQUENCE',
  18, 'CREATE ANY SYNONYM',
  19, 'CREATE ANY TABLE',
  20, 'CREATE ANY TRIGGER',
  21, 'CREATE ANY VIEW',
  22, 'CREATE DATABASE',
  23, 'CREATE MATERIALIZED VIEW',
  24, 'CREATE NODE',
  25, 'CREATE PROCEDURE',
  26, 'CREATE PROFILE',
  27, 'CREATE PUBLIC SYNONYM',
  28, 'CREATE ROLE',
  29, 'CREATE SEQUENCE',
  30, 'CREATE SESSION',
  31, 'CREATE SYNONYM',
  32, 'CREATE TABLE',
  33, 'CREATE TABLESPACE',
  34, 'CREATE TRIGGER',
  35, 'CREATE USER',
  36, 'CREATE VIEW',
  38, 'DROP ANY INDEX',
  39, 'DROP ANY MATERIALIZED VIEW',
  40, 'DROP ANY PROCEDURE',
  41, 'DROP ANY ROLE',
  42, 'DROP ANY SEQUENCE',
  43, 'DROP ANY SYNONYM',
  44, 'DROP ANY TABLE',
  45, 'DROP ANY TRIGGER',
  46, 'DROP ANY VIEW',
  47, 'DROP PROFILE',
  48, 'DROP PUBLIC SYNONYM',
  49, 'DROP TABLESPACE',
  50, 'DROP USER',
  51, 'FLASHBACK ANY TABLE',
  52, 'FLASHBACK ARCHIVE ADMINISTER',
  53, 'GLOBAL QUERY REWRITE',
  54, 'GRANT ANY OBJECT PRIVILEGE',
  55, 'GRANT ANY PRIVILEGE',
  56, 'GRANT ANY ROLE',
  57, 'LOCK ANY TABLE',
  58, 'MANAGE TABLESPACE',
  59, 'ON COMMIT REFRESH',
  60, 'PURGE DBA_RECYCLEBIN',
  61, 'READ ANY TABLE',
  62, 'SELECT ANY SEQUENCE',
  63, 'SELECT ANY TABLE',
  64, 'UNLIMITED TABLESPACE',
  65, 'UNDER ANY VIEW',
  66, 'COMMENT ANY TABLE',
  67, 'UPDATE ANY TABLE',
  68, 'INSERT ANY TABLE',
  69, 'DELETE ANY TABLE',
  70, 'EXECUTE ANY PROCEDURE',
  71, 'SYSBACKUP',
  72, 'SYSDBA',
  73, 'SYSOPER',
  74, 'ANALYZE ANY',
  75, 'DROP NODE',
  76, 'ALTER NODE',
  78, 'CREATE ANY DIRECTORY',
  79, 'DROP ANY DIRECTORY',
  81, 'CREATE ANY SQL MAP',
  82, 'DROP ANY SQL MAP',
  83, 'CREATE ANY TYPE',
  84, 'CREATE TYPE',
  85, 'DROP ANY TYPE',
  86, 'EXECUTE ANY TYPE',
  87, 'CREATE CTRLFILE',
  88, 'CREATE LIBRARY',
  89, 'EXEMPT REDACTION POLICY',
  90, 'CREATE ANY LIBRARY',
  91, 'DROP ANY LIBRARY',
  92, 'EXECUTE ANY LIBRARY', 
  93, 'EXEMPT ACCESS POLICY',
  94, 'INHERIT ANY PRIVILEGES',
  95, 'CREATE TENANT',
  96, 'ALTER TENANT',
  97, 'DROP TENANT',
  98, 'SELECT ANY DICTIONARY',
  99, 'FORCE ANY TRANSACTION',
  100, 'CREATE DATABASE LINK',
  101, 'ALTER DATABASE LINK',
  102, 'DROP DATABASE LINK',
  103, 'USE ANY TABLESPACE',
  'UNKNOWN'),
  DECODE(P.ADMIN_OPTION, 0, 'NO', 'YES')
  FROM SYS.SYS_ROLES R INNER JOIN SYS.SYS_PRIVS P ON R.ID = P.GRANTEE_ID AND P.GRANTEE_TYPE = 1 
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_SYS_PRIVS      FOR SYS.ADM_SYS_PRIVS
/

CREATE OR REPLACE VIEW SYS.MY_SYS_PRIVS
(
  USERNAME,
  PRIVILEGE,
  ADMIN_OPTION
)
AS
  SELECT M.USER_NAME,
  DECODE(P.PRIVILEGE,
  1, 'ALTER ANY INDEX',
  2, 'ALTER ANY MATERIALIZED VIEW',
  3, 'ALTER ANY PROCEDURE',
  4, 'ALTER ANY ROLE',
  5, 'ALTER ANY SEQUENCE',
  6, 'ALTER ANY TABLE',
  7, 'ALTER ANY TRIGGER',
  8, 'ALTER DATABASE',
  9, 'ALTER PROFILE',
  10, 'ALTER SESSION',
  11, 'ALTER SYSTEM',
  12, 'ALTER TABLESPACE',
  13, 'ALTER USER',
  14, 'CREATE ANY INDEX',
  15, 'CREATE ANY MATERIALIZED VIEW',
  16, 'CREATE ANY PROCEDURE',
  17, 'CREATE ANY SEQUENCE',
  18, 'CREATE ANY SYNONYM',
  19, 'CREATE ANY TABLE',
  20, 'CREATE ANY TRIGGER',
  21, 'CREATE ANY VIEW',
  22, 'CREATE DATABASE',
  23, 'CREATE MATERIALIZED VIEW',
  24, 'CREATE NODE',
  25, 'CREATE PROCEDURE',
  26, 'CREATE PROFILE',
  27, 'CREATE PUBLIC SYNONYM',
  28, 'CREATE ROLE',
  29, 'CREATE SEQUENCE',
  30, 'CREATE SESSION',
  31, 'CREATE SYNONYM',
  32, 'CREATE TABLE',
  33, 'CREATE TABLESPACE',
  34, 'CREATE TRIGGER',
  35, 'CREATE USER',
  36, 'CREATE VIEW',
  38, 'DROP ANY INDEX',
  39, 'DROP ANY MATERIALIZED VIEW',
  40, 'DROP ANY PROCEDURE',
  41, 'DROP ANY ROLE',
  42, 'DROP ANY SEQUENCE',
  43, 'DROP ANY SYNONYM',
  44, 'DROP ANY TABLE',
  45, 'DROP ANY TRIGGER',
  46, 'DROP ANY VIEW',
  47, 'DROP PROFILE',
  48, 'DROP PUBLIC SYNONYM',
  49, 'DROP TABLESPACE',
  50, 'DROP USER',
  51, 'FLASHBACK ANY TABLE',
  52, 'FLASHBACK ARCHIVE ADMINISTER',
  53, 'GLOBAL QUERY REWRITE',
  54, 'GRANT ANY OBJECT PRIVILEGE',
  55, 'GRANT ANY PRIVILEGE',
  56, 'GRANT ANY ROLE',
  57, 'LOCK ANY TABLE',
  58, 'MANAGE TABLESPACE',
  59, 'ON COMMIT REFRESH',
  60, 'PURGE DBA_RECYCLEBIN',
  61, 'READ ANY TABLE',
  62, 'SELECT ANY SEQUENCE',
  63, 'SELECT ANY TABLE',
  64, 'UNLIMITED TABLESPACE',
  65, 'UNDER ANY VIEW',
  66, 'COMMENT ANY TABLE',
  67, 'UPDATE ANY TABLE',
  68, 'INSERT ANY TABLE',
  69, 'DELETE ANY TABLE',
  70, 'EXECUTE ANY PROCEDURE',
  71, 'SYSBACKUP',
  72, 'SYSDBA',
  73, 'SYSOPER',
  74, 'ANALYZE ANY',
  75, 'DROP NODE',
  76, 'ALTER NODE',
  78, 'CREATE ANY DIRECTORY',
  79, 'DROP ANY DIRECTORY',
  81, 'CREATE ANY SQL MAP',
  82, 'DROP ANY SQL MAP',
  83, 'CREATE ANY TYPE',
  84, 'CREATE TYPE',
  85, 'DROP ANY TYPE',
  86, 'EXECUTE ANY TYPE',
  87, 'CREATE CTRLFILE',
  88, 'CREATE LIBRARY',
  89, 'EXEMPT REDACTION POLICY',
  90, 'CREATE ANY LIBRARY',
  91, 'DROP ANY LIBRARY',
  92, 'EXECUTE ANY LIBRARY',
  93, 'EXEMPT ACCESS POLICY',
  94, 'INHERIT ANY PRIVILEGES',
  95, 'CREATE TENANT',
  96, 'ALTER TENANT',
  97, 'DROP TENANT',
  98, 'SELECT ANY DICTIONARY',
  99, 'FORCE ANY TRANSACTION',
  100, 'CREATE DATABASE LINK',
  101, 'ALTER DATABASE LINK',
  102, 'DROP DATABASE LINK',
  103, 'USE ANY TABLESPACE',
  'UNKNOWN'),
  DECODE(P.ADMIN_OPTION, 0, 'NO', 'YES')
  FROM SYS.DV_ME M INNER JOIN SYS.SYS_PRIVS P ON M.USER_ID = P.GRANTEE_ID AND P.GRANTEE_TYPE = 0
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_SYS_PRIVS     FOR SYS.MY_SYS_PRIVS
/
GRANT SELECT ON MY_SYS_PRIVS TO PUBLIC
/
--20
CREATE OR REPLACE VIEW SYS.ADM_ROLE_PRIVS
(
  GRANTEE,
  GRANTED_ROLE,
  ADMIN_OPTION
)
AS
  SELECT U.NAME, R.NAME, DECODE(P.ADMIN_OPTION, 0, 'NO', 'YES')
  FROM SYS.SYS_USERS U, SYS.SYS_ROLES R, SYS.SYS_USER_ROLES P
  WHERE P.GRANTEE_TYPE = 0 AND U.ID = P.GRANTEE_ID AND R.ID = P.GRANTED_ROLE_ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT R1.NAME, R2.NAME, DECODE(P.ADMIN_OPTION, 0, 'NO', 'YES')
  FROM SYS.SYS_ROLES R1, SYS.SYS_ROLES R2, SYS.SYS_USER_ROLES P
  WHERE P.GRANTEE_TYPE = 1 AND R1.ID = P.GRANTEE_ID AND R2.ID = P.GRANTED_ROLE_ID
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_ROLE_PRIVS     FOR SYS.ADM_ROLE_PRIVS
/
CREATE OR REPLACE VIEW SYS.MY_ROLE_PRIVS
(
  USERNAME,
  GRANTED_ROLE,
  ADMIN_OPTION
)
AS
  SELECT M.USER_NAME, R.NAME, DECODE(P.ADMIN_OPTION, 0, 'NO', 'YES')
  FROM SYS.DV_ME M, SYS.SYS_ROLES R, SYS.SYS_USER_ROLES P
  WHERE P.GRANTEE_TYPE = 0 AND M.USER_ID = P.GRANTEE_ID AND R.ID = P.GRANTED_ROLE_ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_ROLE_PRIVS    FOR SYS.MY_ROLE_PRIVS
/
GRANT SELECT ON MY_ROLE_PRIVS TO PUBLIC
/
CREATE OR REPLACE VIEW SYS.ADM_TAB_PRIVS
(
  GRANTEE,
  OWNER,
  OBJECT_NAME,
  OBJECT_TYPE,
  PRIVILEGE,
  GRANTABLE
)
AS
  SELECT U1.NAME, U2.NAME, P.OBJECT_NAME,
  DECODE(P.OBJECT_TYPE, 0, 'TABLE', 1, 'VIEW', 2, 'SEQUENCE', 3, 'PROCEDURE', 18, 'DIRECTORY', 21, 'LIBRARY', 25, 'USER', 'UNKNOWN'),
  DECODE(P.PRIVILEGE, 0, 'ALTER', 1, 'DELETE', 2, 'EXECUTE', 3, 'INDEX', 4, 'INSERT', 5, 'READ', 6, 'REFERENCES', 7, 'SELECT', 8, 'UPDATE', 9, 'READ ON DIRECTORY', 10, 'WRITE ON DIRECTORY', 11, 'EXECUTE ON DIRECTORY', 12, 'INHERIT PRIVILEGES', 'UNKNOWN'),
  DECODE(P.GRANTABLE, 0, 'NO', 1, 'YES', '-')
  FROM SYS.SYS_USERS U1, SYS.SYS_USERS U2, SYS.SYS_OBJECT_PRIVS P
  WHERE P.GRANTEE_TYPE = 0 AND U1.ID = P.GRANTEE AND P.OBJECT_OWNER = U2.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U1.TENANT_ID)
  UNION ALL
  SELECT R.NAME, U.NAME, P.OBJECT_NAME,
  DECODE(P.OBJECT_TYPE, 0, 'TABLE', 1, 'VIEW', 2, 'SEQUENCE', 3, 'PROCEDURE', 18, 'DIRECTORY', 21, 'LIBRARY', 25, 'USER', 'UNKNOWN'),
  DECODE(P.PRIVILEGE, 0, 'ALTER', 1, 'DELETE', 2, 'EXECUTE', 3, 'INDEX', 4, 'INSERT', 5, 'READ', 6, 'REFERENCES', 7, 'SELECT', 8, 'UPDATE', 9, 'READ ON DIRECTORY', 10, 'WRITE ON DIRECTORY', 11, 'EXECUTE ON DIRECTORY', 12, 'INHERIT PRIVILEGES', 'UNKNOWN'),
  DECODE(P.GRANTABLE, 0, 'NO', 1, 'YES', '-')
  FROM SYS.SYS_ROLES R, SYS.SYS_USERS U, SYS.SYS_OBJECT_PRIVS P
  WHERE P.GRANTEE_TYPE = 1 AND R.ID = P.GRANTEE AND P.OBJECT_OWNER = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U1.NAME, 'SYS', U2.NAME, 'USER', 
  DECODE(P.PRIVILEGE, 0, 'INHERIT PRIVILEGES', 'UNKNOWN'),
  DECODE(P.OPTION, 0, 'NO', 1, 'YES', '-')
  FROM SYS.SYS_USERS U1, SYS.SYS_USERS U2, SYS.SYS_USER_PRIVS P
  WHERE U1.ID = P.GRANTEE AND U2.ID = P.UID AND DBE_DIAGNOSE.TENANT_CHECK(0, U1.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_TAB_PRIVS   FOR SYS.ADM_TAB_PRIVS
/
CREATE OR REPLACE VIEW SYS.MY_TAB_PRIVS
(
  GRANTEE,
  OWNER,
  OBJECT_NAME,
  OBJECT_TYPE,
  PRIVILEGE,
  GRANTABLE
)
AS
  SELECT M.USER_NAME, U.NAME, P.OBJECT_NAME,
  DECODE(P.OBJECT_TYPE, 0, 'TABLE', 1, 'VIEW', 2, 'SEQUENCE', 3, 'PROCEDURE', 18, 'DIRECTORY', 21, 'LIBRARY', 25, 'USER', 'UNKNOWN'),
  DECODE(P.PRIVILEGE, 0, 'ALTER', 1, 'DELETE', 2, 'EXECUTE', 3, 'INDEX', 4, 'INSERT', 5, 'READ', 6, 'REFERENCES', 7, 'SELECT', 8, 'UPDATE', 9, 'READ ON DIRECTORY', 10, 'WRITE ON DIRECTORY', 11, 'EXECUTE ON DIRECTORY', 12, 'INHERIT PRIVILEGES', 'UNKNOWN'),
  DECODE(P.GRANTABLE, 0, 'NO', 1, 'YES', '-')
  FROM SYS.DV_ME M, SYS.SYS_USERS U, SYS.SYS_OBJECT_PRIVS P
  WHERE P.GRANTEE_TYPE = 0 AND M.USER_ID = P.GRANTEE AND P.OBJECT_OWNER = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT M.USER_NAME, 'SYS', U2.NAME, 'USER', 
  DECODE(P.PRIVILEGE, 0, 'INHERIT PRIVILEGES', 'UNKNOWN'),
  DECODE(P.OPTION, 0, 'NO', 1, 'YES', '-')
  FROM SYS.DV_ME M, SYS.SYS_USERS U2, SYS.SYS_USER_PRIVS P
  WHERE M.USER_ID = P.GRANTEE AND U2.ID = P.UID AND DBE_DIAGNOSE.TENANT_CHECK(0, U2.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM MY_TAB_PRIVS   FOR SYS.MY_TAB_PRIVS
/
GRANT SELECT ON MY_TAB_PRIVS TO PUBLIC
/
--21
CREATE OR REPLACE VIEW ADM_SEQUENCES
(
  SEQUENCE_OWNER,
  SEQUENCE_NAME,
  MIN_VALUE,
  MAX_VALUE,
  INCREMENT_BY,
  CYCLE_FLAG,
  ORDER_FLAG,
  CACHE_SIZE,
  LAST_NUMBER
)
AS
  SELECT U.NAME, SEQ.NAME, SEQ.MINVAL, SEQ.MAXVAL, SEQ.STEP, SEQ.CYCLE_FLAG, SEQ.ORDER_FLAG, SEQ.CACHESIZE, SEQ.LAST_NUMBER
  FROM SYS.SYS_USERS U, SYS.SYS_SEQUENCES SEQ
  WHERE SEQ.UID = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_SEQUENCES    FOR SYS.ADM_SEQUENCES
/
CREATE OR REPLACE VIEW DB_SEQUENCES
(
  SEQUENCE_OWNER,
  SEQUENCE_NAME,
  MIN_VALUE,
  MAX_VALUE,
  INCREMENT_BY,
  CYCLE_FLAG,
  ORDER_FLAG,
  CACHE_SIZE,
  LAST_NUMBER
)
AS
  SELECT U.NAME, SEQ.NAME, SEQ.MINVAL, SEQ.MAXVAL, SEQ.STEP, SEQ.CYCLE_FLAG, SEQ.ORDER_FLAG, SEQ.CACHESIZE, SEQ.LAST_NUMBER
  FROM SYS.SYS_USERS U, SYS.SYS_SEQUENCES SEQ
  WHERE SEQ.UID = U.ID and
        (U.NAME = user or  
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||SEQ.NAME||'"', 'SEQUENCE')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)

/
CREATE OR REPLACE PUBLIC SYNONYM  DB_SEQUENCES      FOR SYS.DB_SEQUENCES
/
GRANT SELECT ON DB_SEQUENCES TO PUBLIC
/
CREATE OR REPLACE VIEW MY_SEQUENCES
(
  SEQUENCE_NAME,
  MIN_VALUE,
  MAX_VALUE,
  INCREMENT_BY,
  CYCLE_FLAG,
  ORDER_FLAG,
  CACHE_SIZE,
  LAST_NUMBER
)
AS
  SELECT SEQ.NAME, SEQ.MINVAL, SEQ.MAXVAL, SEQ.STEP, SEQ.CYCLE_FLAG, SEQ.ORDER_FLAG, SEQ.CACHESIZE, SEQ.LAST_NUMBER
  FROM SYS.DV_ME M, SYS.SYS_SEQUENCES SEQ
  WHERE SEQ.UID = M.USER_ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_SEQUENCES     FOR SYS.MY_SEQUENCES
/
GRANT SELECT ON MY_SEQUENCES TO PUBLIC
/
--22
CREATE OR REPLACE VIEW SYS.DB_IND_COLUMNS
(
INDEX_OWNER,
INDEX_NAME,
TABLE_OWNER,
TABLE_NAME,
COLUMN_NAME,
COLUMN_POSITION,
COLUMN_LENGTH,
ID,
DEFAULT_TEXT
)
AS
 SELECT
    U.NAME,
    I.NAME,
    U.NAME,
    T.NAME,
    C.NAME,
    DBE_DIAGNOSE.DBA_IND_POS(I.COL_LIST::VARCHAR(128), C.ID::VARCHAR(128))::INTEGER,
    C.BYTES,
    C.ID,
    C.DEFAULT_TEXT
 FROM SYS.SYS_USERS U, SYS.SYS_INDEXES I, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
 WHERE
        I.USER# = U.ID
    AND T.USER# = U.ID
    AND C.USER# = U.ID
    AND C.TABLE# = I.TABLE#
    AND T.ID = I.TABLE#
    AND INSTR(',' || I.COL_LIST ||',', ',' || C.ID ||',') > 0
    AND T.RECYCLED = 0
    AND (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_IND_COLUMNS    FOR SYS.DB_IND_COLUMNS
/
GRANT SELECT ON DB_IND_COLUMNS TO PUBLIC
/
CREATE OR REPLACE VIEW SYS.ADM_IND_COLUMNS
(
INDEX_OWNER,
INDEX_NAME,
TABLE_OWNER,
TABLE_NAME,
COLUMN_NAME,
COLUMN_POSITION,
COLUMN_LENGTH
)
AS
 SELECT
    U.NAME,
    I.NAME,
    U.NAME,
    T.NAME,
    C.NAME,
    DBE_DIAGNOSE.DBA_IND_POS(I.COL_LIST::VARCHAR(128), C.ID::VARCHAR(128))::INTEGER,
    C.BYTES
 FROM SYS.SYS_USERS U, SYS.SYS_INDEXES I, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
 WHERE
        I.USER# = U.ID
    AND T.USER# = U.ID
    AND C.USER# = U.ID
    AND C.TABLE# = I.TABLE#
    AND T.ID = I.TABLE#
    AND INSTR(',' || I.COL_LIST ||',', ',' || C.ID ||',') > 0
    AND T.RECYCLED = 0
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_IND_COLUMNS    FOR SYS.ADM_IND_COLUMNS
/
CREATE OR REPLACE VIEW SYS.MY_IND_COLUMNS
(
INDEX_NAME,
TABLE_NAME,
COLUMN_NAME,
COLUMN_POSITION,
COLUMN_LENGTH
)
AS
SELECT I.NAME,
       T.NAME,
       C.NAME,
       DBE_DIAGNOSE.DBA_IND_POS(I.COL_LIST::VARCHAR(128), C.ID::VARCHAR(128))::INTEGER,
       C.BYTES
  FROM SYS.DV_ME ME, SYS.SYS_INDEXES I, SYS.SYS_COLUMNS C, SYS.SYS_TABLES T
  WHERE
        I.USER# = ME.USER_ID
    AND T.USER# = ME.USER_ID
    AND C.USER# = ME.USER_ID
    AND I.TABLE# = T.ID
    AND C.TABLE# = T.ID
    AND INSTR(',' || I.COL_LIST || ',', ',' || C.ID || ',') > 0
    AND T.RECYCLED = 0
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_IND_COLUMNS   FOR SYS.MY_IND_COLUMNS
/
GRANT SELECT ON MY_IND_COLUMNS TO PUBLIC
/
CREATE OR REPLACE VIEW SYS.ADM_DATA_FILES
(
  FILE_NAME,
  FILE_ID,
  TABLESPACE_NAME,
  BYTES,
  BLOCKS,
  STATUS,
  RELATIVE_FNO,
  AUTOEXTENSIBLE,
  MAXBYTES,
  MAXBLOCKS,
  INCREMENT_BY,
  USER_BYTES,
  USER_BLOCKS,
  ONLINE_STATUS
)
AS
  SELECT D.FILE_NAME, D.ID, T.NAME, D.BYTES, (D.BYTES / (RTRIM(P.VALUE, 'Kk')::BINARY_INTEGER * 1024))::BINARY_BIGINT, 'VALID', D.ID, DECODE(D.AUTO_EXTEND, 'TRUE', 'YES', 'NO'),
  D.MAX_SIZE::BINARY_BIGINT,
  (D.MAX_SIZE / (RTRIM(P.VALUE, 'Kk')::BINARY_INTEGER * 1024))::BINARY_BIGINT,
  D.AUTO_EXTEND_SIZE,
  (D.BYTES - 20 * (D.BYTES / (RTRIM(P.VALUE, 'Kk')::BINARY_INTEGER * 1024)))::BINARY_BIGINT,
  ((D.BYTES - 20 * (D.BYTES / (RTRIM(P.VALUE, 'Kk')::BINARY_INTEGER * 1024))) / (RTRIM(P.VALUE, 'Kk')::BINARY_INTEGER * 1024))::BINARY_BIGINT,
  D.STATUS
  FROM SYS.DV_DATA_FILES D, SYS.DV_TABLESPACES T, SYS.DV_PARAMETERS P
  WHERE D.TABLESPACE_ID = T.ID AND P.NAME = 'PAGE_SIZE'
/
CREATE OR REPLACE PUBLIC SYNONYM ADM_DATA_FILES FOR SYS.ADM_DATA_FILES
/
--23
CREATE OR REPLACE VIEW SYS.ADM_TAB_MODIFICATIONS
(
  TABLE_OWNER,
  TABLE_NAME,
  PARTITION_NAME,
  SUBPARTITION_NAME,
  INSERTS,
  UPDATES,
  DELETES,
  TIMESTAMP,   
  DROP_SEGMENTS
) AS	
   SELECT U.NAME, T.NAME, null::VARCHAR(64), null::VARCHAR(64), MO.INSERTS, MO.UPDATES, MO.DELETES, MO.MODIFY_TIME, MO.DROP_SEGMENTS 
   FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON U.ID = T.USER# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
   JOIN SYS.SYS_DML_STATS MO ON T.USER# = MO.USER# AND T.ID = MO.TABLE# WHERE MO.PARTED = 0 OR (MO.PARTED = 1 AND MO.PART#=-1)
UNION ALL
   SELECT U.NAME, T.NAME, TP.NAME, null::VARCHAR(64), MO.INSERTS, MO.UPDATES, MO.DELETES, MO.MODIFY_TIME, MO.DROP_SEGMENTS 
   FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON U.ID = T.USER# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
   JOIN SYS.SYS_TABLE_PARTS TP ON T.USER# = TP.USER# AND T.ID = TP.TABLE#
   JOIN SYS.SYS_DML_STATS MO ON T.USER# = MO.USER# AND T.ID = MO.TABLE# AND MO.PART# = TP.PART# 
   WHERE MO.PARTED = 1 AND MO.PART# <> -1
/
CREATE OR REPLACE VIEW SYS.DB_TAB_MODIFICATIONS
(
  TABLE_OWNER,
  TABLE_NAME,
  PARTITION_NAME,
  SUBPARTITION_NAME,
  INSERTS,
  UPDATES,
  DELETES,
  TIMESTAMP,   
  DROP_SEGMENTS
) AS	
   SELECT U.NAME, T.NAME, null::VARCHAR(64), null::VARCHAR(64), MO.INSERTS, MO.UPDATES, MO.DELETES, MO.MODIFY_TIME, MO.DROP_SEGMENTS 
   FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON U.ID = T.USER# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
   JOIN SYS.SYS_DML_STATS MO ON T.USER# = MO.USER# AND T.ID = MO.TABLE#
   WHERE (MO.PARTED = 0 OR (MO.PARTED = 1 AND MO.PART#=-1)) and T.RECYCLED = 0 AND
         (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
UNION ALL
   SELECT U.NAME, T.NAME, TP.NAME, null::VARCHAR(64), MO.INSERTS, MO.UPDATES, MO.DELETES, MO.MODIFY_TIME, MO.DROP_SEGMENTS 
   FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON U.ID = T.USER# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
   JOIN SYS.SYS_TABLE_PARTS TP ON T.USER# = TP.USER# AND T.ID = TP.TABLE#
   JOIN SYS.SYS_DML_STATS MO ON T.USER# = MO.USER# AND T.ID = MO.TABLE# AND MO.PART# = TP.PART# 
   WHERE T.RECYCLED = 0 AND MO.PARTED = 1 AND MO.PART# <> -1 AND 
         (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
/

CREATE OR REPLACE VIEW SYS.MY_TAB_MODIFICATIONS
(
   TABLE_NAME,
   PARTITION_NAME,
   SUBPARTITION_NAME,
   INSERTS,
   UPDATES,
   DELETES,
   TIMESTAMP,    
   DROP_SEGMENTS
) AS
   SELECT T.NAME, null::VARCHAR(64), null::VARCHAR(64), MO.INSERTS, MO.UPDATES, MO.DELETES, MO.MODIFY_TIME, MO.DROP_SEGMENTS 
   FROM SYS.DV_ME M JOIN SYS.SYS_TABLES T ON M.USER_ID = T.USER# 
   JOIN SYS.SYS_DML_STATS MO ON T.USER# = MO.USER# AND T.ID = MO.TABLE# WHERE MO.PARTED = 0 OR (MO.PARTED = 1 AND MO.PART#=-1)
UNION ALL
   SELECT T.NAME, TP.NAME, null::VARCHAR(64), MO.INSERTS, MO.UPDATES, MO.DELETES, MO.MODIFY_TIME, MO.DROP_SEGMENTS 
   FROM SYS.DV_ME M JOIN SYS.SYS_TABLES T ON M.USER_ID = T.USER# 
   JOIN SYS.SYS_TABLE_PARTS TP ON T.USER# = TP.USER# AND T.ID = TP.TABLE#
   JOIN SYS.SYS_DML_STATS MO ON T.USER# = MO.USER# AND T.ID = MO.TABLE#  AND MO.PART# = TP.PART#
   WHERE MO.PARTED = 1 AND MO.PART# <> -1
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_TAB_MODIFICATIONS      FOR SYS.ADM_TAB_MODIFICATIONS
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_TAB_MODIFICATIONS      FOR SYS.DB_TAB_MODIFICATIONS
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_TAB_MODIFICATIONS      FOR SYS.MY_TAB_MODIFICATIONS
/
GRANT SELECT ON MY_TAB_MODIFICATIONS TO PUBLIC
/

--24
CREATE OR REPLACE VIEW MY_TAB_PARTITIONS AS
SELECT 
T.NAME AS TABLE_NAME,
DECODE(TP.FLAGS & 0x4, 0, 'NO', 'YES')::VARCHAR2(3) AS COMPOSITE,
TP.NAME AS PARTITION_NAME,
DECODE(TP.FLAGS & 0x4, 0, 0, TP.SUBPARTCNT)::NUMBER AS SUBPARTITION_COUNT,
TP.HIBOUNDVAL AS HIGH_VALUE,
TP.HIBOUNDLEN::NUMBER AS HIGH_VALUE_LENGTH,
ROW_NUMBER() OVER (PARTITION BY T.NAME ORDER BY TP.PART#) AS PARTITION_POSITION,
TS.NAME AS TABLESPACE_NAME,
(CASE WHEN TP.PART# < 1073741824 THEN 'N' ELSE 'Y' END) AS INTERVAL,
TP.PCTFREE AS PCT_FREE,
NULL::NUMBER AS PCT_USED,
TP.INITRANS AS INI_TRANS,
NULL::NUMBER AS MAX_TRANS,
NULL::NUMBER AS INITIAL_EXTENT, 
NULL::NUMBER AS NEXT_EXTENT,    
NULL::NUMBER AS MIN_EXTENT,     
NULL::NUMBER AS MAX_EXTENT,     
NULL::NUMBER AS MAX_SIZE,       
NULL::NUMBER AS PCT_INCREASE,   
NULL::NUMBER AS FREELISTS,      
NULL::NUMBER AS FREELIST_GROUPS,
NULL::VARCHAR2(7) AS LOGGING,        
NULL::VARCHAR2(8) AS COMPRESSION,    
NULL::VARCHAR2(18) AS COMPRESS_FOR,
TP.ROWCNT AS NUM_ROWS,
TP.BLKCNT AS BLOCKS,
TP.EMPCNT AS EMPTY_BLOCKS, 
NULL::NUMBER AS   AVG_SPACE,
NULL::NUMBER AS   CHAIN_CNT,
TP.AVGRLN AS AVG_ROW_LEN,
TP.SAMPLESIZE AS SAMPLE_SIZE,
TP.ANALYZETIME AS LAST_ANALYZED,
NULL::VARCHAR2(7) AS BUFFER_POOL,
NULL::VARCHAR2(3) AS GLOBAL_STATS,
NULL::VARCHAR2(3)  AS USER_STATS,
DECODE(TP.FLAGS & 8, 8, 'CSF', 'ASF') AS ROW_FORMAT,
DECODE(TP.FLAGS & 16, 16, 'YES', 'NO') AS NOLOGGING_INSERT,
NVL((select DECODE(CO.COMPRESS_ALGO, 0, 'NONE', 1, 'ZLIB', 2, 'ZSTD', 3, 'LZ4', 'NONE') from SYS.SYS_COMPRESS_OBJECTS CO where CO.ORG_SCN = TP.ORG_SCN AND CO.OBJECT_TYPE = 2), 'NONE') AS COMPRESS_ALGO
FROM SYS.DV_ME M, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS, SYS.SYS_TABLE_PARTS TP
WHERE TP.TABLE#=T.ID AND TP.USER# = T.USER# AND TP.SPACE#=TS.ID AND TP.USER# = M.USER_ID
/
CREATE OR REPLACE PUBLIC SYNONYM MY_TAB_PARTITIONS FOR SYS.MY_TAB_PARTITIONS
/
GRANT SELECT ON MY_TAB_PARTITIONS TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_TAB_PARTITIONS AS
SELECT 
U.NAME AS TABLE_OWNER,
T.NAME AS TABLE_NAME,
DECODE(TP.FLAGS & 0x4, 0, 'NO', 'YES')::VARCHAR2(3) AS COMPOSITE,
TP.NAME AS PARTITION_NAME,
DECODE(TP.FLAGS & 0x4, 0, 0, TP.SUBPARTCNT)::NUMBER AS SUBPARTITION_COUNT,
TP.HIBOUNDVAL AS HIGH_VALUE,
TP.HIBOUNDLEN::NUMBER AS HIGH_VALUE_LENGTH,
ROW_NUMBER() OVER (PARTITION BY U.NAME, T.NAME ORDER BY TP.PART#) AS PARTITION_POSITION,
TS.NAME AS TABLESPACE_NAME,
(CASE WHEN TP.PART# < 1073741824 THEN 'N' ELSE 'Y' END) AS INTERVAL,
TP.PCTFREE AS PCT_FREE,
NULL::NUMBER AS PCT_USED,
TP.INITRANS AS INI_TRANS,
NULL::NUMBER AS MAX_TRANS,
NULL::NUMBER AS INITIAL_EXTENT, 
NULL::NUMBER AS NEXT_EXTENT,    
NULL::NUMBER AS MIN_EXTENT,     
NULL::NUMBER AS MAX_EXTENT,     
NULL::NUMBER AS MAX_SIZE,       
NULL::NUMBER AS PCT_INCREASE,   
NULL::NUMBER AS FREELISTS,      
NULL::NUMBER AS FREELIST_GROUPS,
NULL::VARCHAR2(7) AS LOGGING,        
NULL::VARCHAR2(8) AS COMPRESSION,    
NULL::VARCHAR2(18) AS COMPRESS_FOR,
TP.ROWCNT AS NUM_ROWS,
TP.BLKCNT AS BLOCKS,
TP.EMPCNT AS EMPTY_BLOCKS, 
NULL::NUMBER AS   AVG_SPACE,
NULL::NUMBER AS   CHAIN_CNT,
TP.AVGRLN AS AVG_ROW_LEN,
TP.SAMPLESIZE AS SAMPLE_SIZE,
TP.ANALYZETIME AS LAST_ANALYZED,
NULL::VARCHAR2(7) AS BUFFER_POOL,
NULL::VARCHAR2(3) AS GLOBAL_STATS,
NULL::VARCHAR2(3)  AS USER_STATS,
DECODE(TP.FLAGS & 8, 8, 'CSF', 'ASF') AS ROW_FORMAT,
DECODE(TP.FLAGS & 16, 16, 'YES', 'NO') AS NOLOGGING_INSERT,
NVL((select DECODE(CO.COMPRESS_ALGO, 0, 'NONE', 1, 'ZLIB', 2, 'ZSTD', 3, 'LZ4', 'NONE') from SYS.SYS_COMPRESS_OBJECTS CO where CO.ORG_SCN = TP.ORG_SCN AND CO.OBJECT_TYPE = 2), 'NONE') AS COMPRESS_ALGO
FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS, SYS.SYS_TABLE_PARTS TP
WHERE TP.USER# = U.ID AND TP.USER# = T.USER# AND TP.TABLE#=T.ID AND TP.SPACE#=TS.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_TAB_PARTITIONS FOR SYS.ADM_TAB_PARTITIONS
/
CREATE OR REPLACE VIEW DB_TAB_PARTITIONS AS
SELECT 
U.NAME AS TABLE_OWNER,
T.NAME AS TABLE_NAME,
DECODE(TP.FLAGS & 0x4, 0, 'NO', 'YES')::VARCHAR2(3) AS COMPOSITE,
TP.NAME AS PARTITION_NAME,
DECODE(TP.FLAGS & 0x4, 0, 0, TP.SUBPARTCNT)::NUMBER AS SUBPARTITION_COUNT,
TP.HIBOUNDVAL AS HIGH_VALUE,
TP.HIBOUNDLEN::NUMBER AS HIGH_VALUE_LENGTH,
ROW_NUMBER() OVER (PARTITION BY U.NAME, T.NAME ORDER BY TP.PART#) AS PARTITION_POSITION,
TS.NAME AS TABLESPACE_NAME,
(CASE WHEN TP.PART# < 1073741824 THEN 'N' ELSE 'Y' END) AS INTERVAL,
TP.PCTFREE AS PCT_FREE,
NULL::NUMBER AS PCT_USED,
TP.INITRANS AS INI_TRANS,
NULL::NUMBER AS MAX_TRANS,
NULL::NUMBER AS INITIAL_EXTENT, 
NULL::NUMBER AS NEXT_EXTENT,    
NULL::NUMBER AS MIN_EXTENT,     
NULL::NUMBER AS MAX_EXTENT,     
NULL::NUMBER AS MAX_SIZE,       
NULL::NUMBER AS PCT_INCREASE,   
NULL::NUMBER AS FREELISTS,      
NULL::NUMBER AS FREELIST_GROUPS,
NULL::VARCHAR2(7) AS LOGGING,        
NULL::VARCHAR2(8) AS COMPRESSION,    
NULL::VARCHAR2(18) AS COMPRESS_FOR,
TP.ROWCNT AS NUM_ROWS,
TP.BLKCNT AS BLOCKS,
TP.EMPCNT AS EMPTY_BLOCKS, 
NULL::NUMBER AS   AVG_SPACE,
NULL::NUMBER AS   CHAIN_CNT,
TP.AVGRLN AS AVG_ROW_LEN,
TP.SAMPLESIZE AS SAMPLE_SIZE,
TP.ANALYZETIME AS LAST_ANALYZED,
NULL::VARCHAR2(7) AS BUFFER_POOL,
NULL::VARCHAR2(3) AS GLOBAL_STATS,
NULL::VARCHAR2(3)  AS USER_STATS,
DECODE(TP.FLAGS & 8, 8, 'CSF', 'ASF') AS ROW_FORMAT,
DECODE(TP.FLAGS & 16, 16, 'YES', 'NO') AS NOLOGGING_INSERT,
NVL((select DECODE(CO.COMPRESS_ALGO, 0, 'NONE', 1, 'ZLIB', 2, 'ZSTD', 3, 'LZ4', 'NONE') from SYS.SYS_COMPRESS_OBJECTS CO where CO.ORG_SCN = TP.ORG_SCN AND CO.OBJECT_TYPE = 2), 'NONE') AS COMPRESS_ALGO
FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS, SYS.SYS_TABLE_PARTS TP
WHERE TP.USER# = U.ID AND TP.USER# = T.USER# AND TP.TABLE#=T.ID AND TP.SPACE#=TS.ID
AND T.RECYCLED = 0 AND
    (U.NAME = user or 
     user = 'SYS' or 
     DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_TAB_PARTITIONS FOR SYS.DB_TAB_PARTITIONS
/
GRANT SELECT ON DB_TAB_PARTITIONS TO PUBLIC
/
CREATE OR REPLACE VIEW MY_TAB_SUBPARTITIONS AS
SELECT 
T.NAME AS TABLE_NAME,
TP.NAME::VARCHAR(64) AS PARENTPART_NAME,
TSUBP.NAME AS PARTITION_NAME,
TSUBP.HIBOUNDVAL AS HIGH_VALUE,
TSUBP.HIBOUNDLEN::NUMBER AS HIGH_VALUE_LENGTH,
ROW_NUMBER() OVER (PARTITION BY T.NAME, TP.NAME ORDER BY TSUBP.SUBPART#) AS PARTITION_POSITION,
TS.NAME AS TABLESPACE_NAME,
TSUBP.PCTFREE AS PCT_FREE,
NULL::NUMBER AS PCT_USED,
TSUBP.INITRANS AS INI_TRANS,
NULL::NUMBER AS MAX_TRANS,
NULL::NUMBER AS INITIAL_EXTENT, 
NULL::NUMBER AS NEXT_EXTENT,    
NULL::NUMBER AS MIN_EXTENT,     
NULL::NUMBER AS MAX_EXTENT,     
NULL::NUMBER AS MAX_SIZE,       
NULL::NUMBER AS PCT_INCREASE,   
NULL::NUMBER AS FREELISTS,      
NULL::NUMBER AS FREELIST_GROUPS,
NULL::VARCHAR2(7) AS LOGGING,        
NULL::VARCHAR2(8) AS COMPRESSION,    
NULL::VARCHAR2(18) AS COMPRESS_FOR,
TSUBP.ROWCNT AS NUM_ROWS,
TSUBP.BLKCNT AS BLOCKS,
TSUBP.EMPCNT AS EMPTY_BLOCKS, 
NULL::NUMBER AS   AVG_SPACE,
NULL::NUMBER AS   CHAIN_CNT,
TSUBP.AVGRLN AS AVG_ROW_LEN,
TSUBP.SAMPLESIZE AS SAMPLE_SIZE,
TSUBP.ANALYZETIME AS LAST_ANALYZED,
NULL::VARCHAR2(7) AS BUFFER_POOL,
NULL::VARCHAR2(3) AS GLOBAL_STATS,
NULL::VARCHAR2(3)  AS USER_STATS,
DECODE(TSUBP.FLAGS & 16, 16, 'YES', 'NO') AS NOLOGGING_INSERT,
DECODE(TSUBP.FLAGS & 8, 8, 'CSF', 'ASF') AS ROW_FORMAT 
FROM SYS.DV_ME M, SYS.SYS_SUB_TABLE_PARTS TSUBP, SYS.SYS_TABLE_PARTS TP, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS
WHERE TSUBP.PARENT_PART# = TP.PART# AND TSUBP.USER#=TP.USER# AND TSUBP.TABLE#=T.ID AND TSUBP.TABLE#=TP.TABLE# AND TSUBP.USER#=T.USER# AND TSUBP.SPACE#=TS.ID AND TSUBP.USER#=M.USER_ID AND (TP.FLAGS & 0x4)
/

CREATE OR REPLACE VIEW ADM_TAB_SUBPARTITIONS AS
SELECT 
U.NAME AS TABLE_OWNER,
T.NAME AS TABLE_NAME,
TP.NAME::VARCHAR(64) AS PARENTPART_NAME,
TSUBP.NAME AS PARTITION_NAME,
TSUBP.HIBOUNDVAL AS HIGH_VALUE,
TSUBP.HIBOUNDLEN::NUMBER AS HIGH_VALUE_LENGTH,
ROW_NUMBER() OVER (PARTITION BY U.NAME, T.NAME, TP.NAME ORDER BY TSUBP.SUBPART#) AS PARTITION_POSITION,
TS.NAME AS TABLESPACE_NAME,
TSUBP.PCTFREE AS PCT_FREE,
NULL::NUMBER AS PCT_USED,
TSUBP.INITRANS AS INI_TRANS,
NULL::NUMBER AS MAX_TRANS,
NULL::NUMBER AS INITIAL_EXTENT, 
NULL::NUMBER AS NEXT_EXTENT,    
NULL::NUMBER AS MIN_EXTENT,     
NULL::NUMBER AS MAX_EXTENT,     
NULL::NUMBER AS MAX_SIZE,       
NULL::NUMBER AS PCT_INCREASE,   
NULL::NUMBER AS FREELISTS,      
NULL::NUMBER AS FREELIST_GROUPS,
NULL::VARCHAR2(7) AS LOGGING,        
NULL::VARCHAR2(8) AS COMPRESSION,    
NULL::VARCHAR2(18) AS COMPRESS_FOR,
TSUBP.ROWCNT AS NUM_ROWS,
TSUBP.BLKCNT AS BLOCKS,
TSUBP.EMPCNT AS EMPTY_BLOCKS, 
NULL::NUMBER AS   AVG_SPACE,
NULL::NUMBER AS   CHAIN_CNT,
TSUBP.AVGRLN AS AVG_ROW_LEN,
TSUBP.SAMPLESIZE AS SAMPLE_SIZE,
TSUBP.ANALYZETIME AS LAST_ANALYZED,
NULL::VARCHAR2(7) AS BUFFER_POOL,
NULL::VARCHAR2(3) AS GLOBAL_STATS,
NULL::VARCHAR2(3)  AS USER_STATS,
DECODE(TSUBP.FLAGS & 16, 16, 'YES', 'NO') AS NOLOGGING_INSERT,
DECODE(TSUBP.FLAGS & 8, 8, 'CSF', 'ASF') AS ROW_FORMAT 
FROM SYS.SYS_USERS U, SYS.SYS_SUB_TABLE_PARTS TSUBP, SYS.SYS_TABLE_PARTS TP, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS
WHERE TSUBP.PARENT_PART# = TP.PART# AND TSUBP.USER#=TP.USER# AND TSUBP.USER#=U.ID AND TSUBP.USER#=T.USER# AND TSUBP.TABLE#=T.ID AND TSUBP.TABLE#=TP.TABLE# AND TSUBP.SPACE#=TS.ID AND (TP.FLAGS & 0x4) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/

CREATE OR REPLACE VIEW DB_TAB_SUBPARTITIONS AS
SELECT 
U.NAME AS TABLE_OWNER,
T.NAME AS TABLE_NAME,
TP.NAME::VARCHAR(64) AS PARENTPART_NAME,
TSUBP.NAME::VARCHAR(64) AS PARTITION_NAME,
TSUBP.HIBOUNDVAL AS HIGH_VALUE,
TSUBP.HIBOUNDLEN::NUMBER AS HIGH_VALUE_LENGTH,
ROW_NUMBER() OVER (PARTITION BY U.NAME, T.NAME, TP.NAME ORDER BY TSUBP.SUBPART#) AS PARTITION_POSITION,
TS.NAME AS TABLESPACE_NAME,
TSUBP.PCTFREE AS PCT_FREE,
NULL::NUMBER AS PCT_USED,
TSUBP.INITRANS AS INI_TRANS,
NULL::NUMBER AS MAX_TRANS,
NULL::NUMBER AS INITIAL_EXTENT, 
NULL::NUMBER AS NEXT_EXTENT,    
NULL::NUMBER AS MIN_EXTENT,     
NULL::NUMBER AS MAX_EXTENT,     
NULL::NUMBER AS MAX_SIZE,       
NULL::NUMBER AS PCT_INCREASE,   
NULL::NUMBER AS FREELISTS,      
NULL::NUMBER AS FREELIST_GROUPS,
NULL::VARCHAR2(7) AS LOGGING,        
NULL::VARCHAR2(8) AS COMPRESSION,    
NULL::VARCHAR2(18) AS COMPRESS_FOR,
TSUBP.ROWCNT AS NUM_ROWS,
TSUBP.BLKCNT AS BLOCKS,
TSUBP.EMPCNT AS EMPTY_BLOCKS, 
NULL::NUMBER AS   AVG_SPACE,
NULL::NUMBER AS   CHAIN_CNT,
TSUBP.AVGRLN AS AVG_ROW_LEN,
TSUBP.SAMPLESIZE AS SAMPLE_SIZE,
TSUBP.ANALYZETIME AS LAST_ANALYZED,
NULL::VARCHAR2(7) AS BUFFER_POOL,
NULL::VARCHAR2(3) AS GLOBAL_STATS,
NULL::VARCHAR2(3)  AS USER_STATS,
DECODE(TSUBP.FLAGS & 16, 16, 'YES', 'NO') AS NOLOGGING_INSERT,
DECODE(TSUBP.FLAGS & 8, 8, 'CSF', 'ASF') AS ROW_FORMAT 
FROM SYS.SYS_USERS U, SYS.SYS_SUB_TABLE_PARTS TSUBP, SYS.SYS_TABLE_PARTS TP, SYS.SYS_TABLES T, SYS.DV_TABLESPACES TS
WHERE TSUBP.PARENT_PART#=TP.PART# AND TSUBP.USER#=TP.USER# AND TSUBP.USER#=U.ID AND TSUBP.USER# = T.USER# AND TSUBP.TABLE#=T.ID AND TSUBP.TABLE#=TP.TABLE# AND TSUBP.SPACE#=TS.ID AND (TP.FLAGS & 0x4)
AND T.RECYCLED = 0 AND
    (U.NAME = user or 
     user = 'SYS' or 
     DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/

CREATE OR REPLACE PUBLIC SYNONYM  ADM_TAB_SUBPARTITIONS FOR SYS.ADM_TAB_SUBPARTITIONS
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_TAB_SUBPARTITIONS FOR SYS.DB_TAB_SUBPARTITIONS
/
GRANT SELECT ON DB_TAB_SUBPARTITIONS TO PUBLIC
/
CREATE OR REPLACE PUBLIC SYNONYM MY_TAB_SUBPARTITIONS FOR SYS.MY_TAB_SUBPARTITIONS
/
GRANT SELECT ON MY_TAB_SUBPARTITIONS TO PUBLIC
/
--25
CREATE OR REPLACE VIEW MY_PROCEDURES
(
  OBJECT_NAME,
  PROCEDURE_NAME,
  OBJECT_ID,
  SUBPROGRAM_ID,
  OVERLOAD,
  OBJECT_TYPE,
  AGGREGATE,
  PIPELINED,
  SOURCE,
  STATUS
)
AS
  SELECT P.NAME, NULL::VARCHAR(128), P.OBJ#, 1, NULL::VARCHAR2(40), DECODE(P.TYPE, 'T', 'TRIGGER', 'F', 'FUNCTION', 'P', 'PROCEDURE', 'S', 'PACKAGE SPEC', 'B', 'PACKAGE BODY', 'Y', 'TYPE SPEC', 'O', 'TYPE BODY', 'UNKNOWN'), 
  DECODE(P.AGGREGATE, 0, 'NO', 'YES')::VARCHAR2(3), DECODE(P.PIPELINED, 0, 'NO', 'YES')::VARCHAR2(3), P.SOURCE, DECODE(P.STATUS, 0, 'INVALID', 1, 'VALID', 'UNKNOWN')::VARCHAR2(7)
  FROM SYS.DV_ME ME, SYS.SYS_PROCS P WHERE P.USER# = ME.USER_ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_PROCEDURES       FOR SYS.MY_PROCEDURES 
/
GRANT SELECT ON MY_PROCEDURES TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_PROCEDURES
(
  OWNER,
  OBJECT_NAME,
  PROCEDURE_NAME,
  OBJECT_ID,
  SUBPROGRAM_ID,
  OVERLOAD,
  OBJECT_TYPE,
  AGGREGATE,
  PIPELINED,
  SOURCE,
  STATUS
)
AS
  SELECT U.NAME, P.NAME, NULL::VARCHAR(128), P.OBJ#, 1, NULL::VARCHAR2(40), DECODE(P.TYPE, 'T', 'TRIGGER', 'F', 'FUNCTION', 'P', 'PROCEDURE', 'S', 'PACKAGE SPEC', 'B', 'PACKAGE BODY', 'Y', 'TYPE SPEC', 'O', 'TYPE BODY', 'UNKNOWN'), 
  DECODE(P.AGGREGATE, 0, 'NO', 'YES')::VARCHAR2(3), DECODE(P.PIPELINED, 0, 'NO', 'YES')::VARCHAR2(3), P.SOURCE, DECODE(P.STATUS, 0, 'INVALID', 1, 'VALID', 'UNKNOWN')::VARCHAR2(7)
  FROM SYS.SYS_USERS U, SYS.SYS_PROCS P WHERE P.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/ 
CREATE OR REPLACE PUBLIC SYNONYM  ADM_PROCEDURES    FOR SYS.ADM_PROCEDURES
/
CREATE OR REPLACE VIEW DB_PROCEDURES
(
  OWNER,
  OBJECT_NAME,
  PROCEDURE_NAME,
  OBJECT_ID,
  SUBPROGRAM_ID,
  OVERLOAD,
  OBJECT_TYPE,
  AGGREGATE,
  PIPELINED,
  SOURCE,
  STATUS
)
AS
  SELECT U.NAME, P.NAME, NULL::VARCHAR(128), P.OBJ#, 1, NULL::VARCHAR2(40), DECODE(P.TYPE, 'T', 'TRIGGER', 'F', 'FUNCTION', 'P', 'PROCEDURE', 'S', 'PACKAGE SPEC', 'B', 'PACKAGE BODY', 'Y', 'TYPE SPEC', 'O', 'TYPE BODY', 'UNKNOWN'), 
  DECODE(P.AGGREGATE, 0, 'NO', 'YES')::VARCHAR2(3), DECODE(P.PIPELINED, 0, 'NO', 'YES')::VARCHAR2(3), P.SOURCE, DECODE(P.STATUS, 0, 'INVALID', 1, 'VALID', 'UNKNOWN')::VARCHAR2(7)
  FROM SYS.SYS_USERS U, SYS.SYS_PROCS P 
  WHERE P.USER# = U.ID and    
        (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||P.NAME||'"', P.TYPE)) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_PROCEDURES    FOR SYS.DB_PROCEDURES 
/
GRANT SELECT ON DB_PROCEDURES TO PUBLIC
/
--26
CREATE OR REPLACE VIEW SYS.ADM_USERS
(
  USERNAME,
  USER_ID,
  ACCOUNT_STATUS,
  LOCK_DATE,
  EXPIRY_DATE,
  DEFAULT_TABLESPACE,
  TEMPORARY_TABLESPACE,
  CREATED,
  PROFILE,
  INITIAL_RSRC_CONSUMER_GROUP,
  AUTHENTICATION_TYPE
)
AS
  SELECT DISTINCT U.NAME, U.ID,
  DECODE(U.ASTATUS,
  0, 'OPEN',
  1, 'EXPIRED',
  2, 'EXPIRED(GRACE)',
  4, 'LOCKED(TIMED)',
  5, 'EXPIRED & LOCKED(TIMED)',
  6, 'EXPIRED(GRACE) & LOCKED(TIMED)',
  8, 'LOCKED',
  9, 'EXPIRED & LOCKED',
  10, 'EXPIRED(GRACE) & LOCKED',
  16, 'PERMANENT',
  17, 'PERMANENT & EXPIRED',
  18, 'PERMANENT & EXPIRED(GRACE)',
  20, 'PERMANENT & LOCKED(TIMED)',
  21, 'PERMANENT & EXPIRED & LOCKED(TIMED)',
  22, 'PERMANENT & EXPIRED(GRACE) & LOCKED(TIMED)',
  24, 'PERMANENT & LOCKED',
  25, 'PERMANENT & EXPIRED & LOCKED',
  26, 'PERMANENT & EXPIRED(GRACE) & LOCKED', 'UNKNOWN'),
  U.LTIME, U.EXPTIME, S1.NAME, S2.NAME, U.CTIME, P.NAME, DECODE(U.ID, 0, 'SYS_GROUP', 'DEFAULT_CONSUMER_GROUP'), 'PASSWORD'
  FROM SYS.SYS_USERS U, SYS.SYS_PROFILE P, SYS.DV_TABLESPACES S1, SYS.DV_TABLESPACES S2
  WHERE U.DATA_SPACE# = S1.ID AND U.TEMP_SPACE# = S2.ID AND U.PROFILE# = P.PROFILE# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM ADM_USERS FOR SYS.ADM_USERS
/
CREATE OR REPLACE VIEW SYS.MY_USERS
(
  USERNAME,
  USER_ID,
  ACCOUNT_STATUS,
  LOCK_DATE,
  EXPIRY_DATE,
  DEFAULT_TABLESPACE,
  TEMPORARY_TABLESPACE,
  CREATED,
  INITIAL_RSRC_CONSUMER_GROUP
)
AS
  SELECT U.NAME, U.ID,
  DECODE(U.ASTATUS,
  0, 'OPEN',
  1, 'EXPIRED',
  2, 'EXPIRED(GRACE)',
  4, 'LOCKED(TIMED)',
  5, 'EXPIRED & LOCKED(TIMED)',
  6, 'EXPIRED(GRACE) & LOCKED(TIMED)',
  8, 'LOCKED',
  9, 'EXPIRED & LOCKED',
  10, 'EXPIRED(GRACE) & LOCKED',
  16, 'PERMANENT',
  17, 'PERMANENT & EXPIRED',
  18, 'PERMANENT & EXPIRED(GRACE)',
  20, 'PERMANENT & LOCKED(TIMED)',
  21, 'PERMANENT & EXPIRED & LOCKED(TIMED)',
  22, 'PERMANENT & EXPIRED(GRACE) & LOCKED(TIMED)',
  24, 'PERMANENT & LOCKED',
  25, 'PERMANENT & EXPIRED & LOCKED',
  26, 'PERMANENT & EXPIRED(GRACE) & LOCKED', 'UNKNOWN'),
  U.LTIME, U.EXPTIME, S1.NAME, S2.NAME, U.CTIME, DECODE(U.ID, 0, 'SYS_GROUP', 'DEFAULT_CONSUMER_GROUP')
  FROM SYS.DV_ME M, SYS.SYS_USERS U, SYS.DV_TABLESPACES S1, SYS.DV_TABLESPACES S2
  WHERE U.DATA_SPACE# = S1.ID AND U.TEMP_SPACE# = S2.ID AND U.ID = M.USER_ID
/
CREATE OR REPLACE PUBLIC SYNONYM MY_USERS FOR SYS.MY_USERS
/
GRANT SELECT ON MY_USERS TO PUBLIC
/
--27
CREATE OR REPLACE VIEW SYS.ADM_CONSTRAINTS
(
  OWNER,
  CONSTRAINT_NAME,
  CONSTRAINT_TYPE,
  TABLE_NAME,
  SEARCH_CONDITION,
  R_OWNER,
  R_TABLE_NAME,
  R_CONSTRAINT_NAME,
  DELETE_RULE,
  STATUS,
  DEFERRABLE,
  DEFERRED,
  VALIDATED,
  BAD,
  RELY,
  INDEX_OWNER,
  INDEX_NAME,
  INVALID,
  VIEW_RELATED,
  CONS_COLS,
  REF_COLS,
  SYS_GENERATE,
  IS_DUPLICATE
)
AS
  SELECT U1.NAME, C.CONS_NAME, 'R', T.NAME, C.COND_TEXT, U2.NAME, T3.NAME, I.NAME,
    DECODE(C.REFACT, 1, 'DELETE CASCADE', 2, 'SET NULL', 'NOT ALLOWED') DELETE_RULE, DECODE(C.FLAGS & 2, 2, 'ENABLED', 'DISABLED'), 'NOT DEFERRABLE', 'IMMEDIATE', DECODE(C.FLAGS & 4, 4, 'VALIDATED', 'NOT VALIDATED'), '', '', '', '', 'FALSE', '', 
    DBE_DIAGNOSE.DBA_LISTCOLS(U1.NAME, '"'||T.NAME||'"', C.COL_LIST) CONS_COLS, DBE_DIAGNOSE.DBA_LISTCOLS(U3.NAME, '"'||T3.NAME||'"', I.COL_LIST) REF_COLS, DECODE(C.FLAGS & 8, 8, 'Y', 'N') SYS_GENERATE, DECODE(C.FLAGS & 1024, 0, 'N', 'Y') IS_DUPLICATE
  FROM SYS.SYS_USERS U1, SYS.SYS_USERS U2, SYS.SYS_USERS U3, SYS.SYS_CONSTRAINT_DEFS C, SYS.SYS_TABLES T, SYS.SYS_INDEXES I, SYS.SYS_TABLES T3
  WHERE C.CONS_TYPE = 2 AND U1.ID = C.USER# AND (C.USER# = T.USER# AND T.ID = C.TABLE#) AND C.REF_USER# = I.USER# AND C.REF_TABLE# = I.TABLE# AND C.REF_CONS = I.ID AND C.REF_USER# = U2.ID AND T.RECYCLED = 0
    AND I.USER# = U3.ID AND I.TABLE# = T3.ID AND I.USER# = T3.USER#
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U1.TENANT_ID)
  UNION ALL
  SELECT U1.NAME, C.CONS_NAME, DECODE(C.CONS_TYPE, 0, 'P', 1, 'U', ''), T.NAME, C.COND_TEXT, '', '', '',
    '', DECODE(C.FLAGS & 2, 2, 'ENABLED', 'DISABLED'), 'NOT DEFERRABLE', 'IMMEDIATE', DECODE(C.FLAGS & 4, 4, 'VALIDATED', 'NOT VALIDATED'), '', '', U1.NAME, I.NAME, 'FALSE', '', 
    DBE_DIAGNOSE.DBA_LISTCOLS(U1.NAME, '"'||T.NAME||'"', C.COL_LIST) CONS_COLS, '' REF_COLS, DECODE(C.FLAGS & 8, 8, 'Y', 'N') SYS_GENERATE, DECODE(C.FLAGS & 1024, 0, 'N', 'Y') IS_DUPLICATE 
  FROM SYS.SYS_USERS U1, SYS.SYS_CONSTRAINT_DEFS C, SYS.SYS_TABLES T, SYS.SYS_INDEXES I
  WHERE (C.CONS_TYPE = 0 OR C.CONS_TYPE = 1) AND U1.ID = C.USER# AND (C.USER# = T.USER# AND T.ID = C.TABLE#) 
    AND C.COL_LIST = I.COL_LIST AND C.USER# = I.USER# AND C.TABLE# = I.TABLE# AND T.RECYCLED = 0
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U1.TENANT_ID)
  UNION ALL
  SELECT U.NAME, C.CONS_NAME, 'C',  T.NAME, C.COND_TEXT, '', '', '',
    '', DECODE(C.FLAGS & 2, 2, 'ENABLED', 'DISABLED'), 'NOT DEFERRABLE', 'IMMEDIATE', DECODE(C.FLAGS & 4, 4, 'VALIDATED', 'NOT VALIDATED'), '', '', '', '', 'FALSE', '', DBE_DIAGNOSE.DBA_LISTCOLS(U.NAME, '"'||T.NAME||'"', C.COL_LIST) CONS_COLS, '' REF_COLS, DECODE(C.FLAGS & 8, 8, 'Y', 'N') SYS_GENERATE, DECODE(C.FLAGS & 1024, 0, 'N', 'Y') IS_DUPLICATE
  FROM SYS.SYS_USERS U, SYS.SYS_CONSTRAINT_DEFS C, SYS.SYS_TABLES T
  WHERE C.CONS_TYPE = 3 AND U.ID = C.USER# AND (C.USER# = T.USER# AND T.ID = C.TABLE# AND T.RECYCLED = 0) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM ADM_CONSTRAINTS FOR SYS.ADM_CONSTRAINTS
/
CREATE OR REPLACE VIEW DB_CONSTRAINTS
(
  OWNER,
  CONSTRAINT_NAME,
  CONSTRAINT_TYPE,
  TABLE_NAME,
  SEARCH_CONDITION,
  R_OWNER,
  R_TABLE_NAME,
  R_CONSTRAINT_NAME,
  DELETE_RULE,
  STATUS,
  DEFERRABLE,
  DEFERRED,
  VALIDATED,
  BAD,
  RELY,
  INDEX_OWNER,
  INDEX_NAME,
  INVALID,
  VIEW_RELATED,
  CONS_COLS,
  REF_COLS,
  SYS_GENERATE,
  IS_DUPLICATE
)
AS
  SELECT U1.NAME, C.CONS_NAME, 'R', T.NAME, C.COND_TEXT, U2.NAME, T3.NAME, I.NAME,
    DECODE(C.REFACT, 1, 'DELETE CASCADE', 2, 'SET NULL', 'NOT ALLOWED') DELETE_RULE, DECODE(C.FLAGS & 2, 2, 'ENABLED', 'DISABLED'), 'NOT DEFERRABLE', 'IMMEDIATE', DECODE(C.FLAGS & 4, 4, 'VALIDATED', 'NOT VALIDATED'), '', '', '', '', 'FALSE', '', 
    DBE_DIAGNOSE.DBA_LISTCOLS(U1.NAME, '"'||T.NAME||'"', C.COL_LIST) CONS_COLS, DBE_DIAGNOSE.DBA_LISTCOLS(U3.NAME, '"'||T3.NAME||'"', I.COL_LIST) REF_COLS, DECODE(C.FLAGS & 8, 8, 'Y', 'N') SYS_GENERATE, DECODE(C.FLAGS & 1024, 0, 'N', 'Y') IS_DUPLICATE 
  FROM SYS.SYS_USERS U1, SYS.SYS_USERS U2, SYS.SYS_CONSTRAINT_DEFS C, SYS.SYS_TABLES T, SYS.SYS_INDEXES I, SYS.SYS_USERS U3, SYS.SYS_TABLES T3
  WHERE C.USER# = U1.ID AND T.USER# = U1.ID AND T.ID = C.TABLE# AND C.REF_USER# = I.USER# AND C.REF_USER# = U2.ID AND C.REF_TABLE# = I.TABLE# AND C.REF_CONS = I.ID AND T.RECYCLED = 0
    AND I.USER# = U3.ID AND T3.USER# = U3.ID AND I.TABLE# = T3.ID AND C.CONS_TYPE = 2
    AND (U1.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U1.NAME, '"'||T.NAME||'"', 'TABLE'))
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U1.TENANT_ID)
  UNION ALL
  SELECT U1.NAME, C.CONS_NAME, DECODE(C.CONS_TYPE, 0, 'P', 1, 'U', ''), T.NAME, C.COND_TEXT, '', '', '',
    '', DECODE(C.FLAGS & 2, 2, 'ENABLED', 'DISABLED'), 'NOT DEFERRABLE', 'IMMEDIATE', DECODE(C.FLAGS & 4, 4, 'VALIDATED', 'NOT VALIDATED'), '', '', U1.NAME, I.NAME, 'FALSE', '', 
    DBE_DIAGNOSE.DBA_LISTCOLS(U1.NAME, '"'||T.NAME||'"', C.COL_LIST) CONS_COLS, '' REF_COLS, DECODE(C.FLAGS & 8, 8, 'Y', 'N') SYS_GENERATE, DECODE(C.FLAGS & 1024, 0, 'N', 'Y') IS_DUPLICATE 
  FROM SYS.SYS_USERS U1, SYS.SYS_CONSTRAINT_DEFS C, SYS.SYS_TABLES T, SYS.SYS_INDEXES I
  WHERE C.USER# = U1.ID AND T.USER# = U1.ID AND T.ID = C.TABLE#
    AND C.COL_LIST = I.COL_LIST AND C.USER# = I.USER# AND C.TABLE# = I.TABLE# AND T.RECYCLED = 0 AND (C.CONS_TYPE = 0 OR C.CONS_TYPE = 1)
    AND (U1.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U1.NAME, '"'||T.NAME||'"', 'TABLE'))
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U1.TENANT_ID)
  UNION ALL
  SELECT U.NAME, C.CONS_NAME, 'C',  T.NAME, C.COND_TEXT, '', '', '',
    '', DECODE(C.FLAGS & 2, 2, 'ENABLED', 'DISABLED'), 'NOT DEFERRABLE', 'IMMEDIATE', DECODE(C.FLAGS & 4, 4, 'VALIDATED', 'NOT VALIDATED'), '', '', '', '', 'FALSE', '', DBE_DIAGNOSE.DBA_LISTCOLS(U.NAME, '"'||T.NAME||'"', C.COL_LIST) CONS_COLS, '' REF_COLS, DECODE(C.FLAGS & 8, 8, 'Y', 'N') SYS_GENERATE, DECODE(C.FLAGS & 1024, 0, 'N', 'Y') IS_DUPLICATE 
  FROM SYS.SYS_USERS U, SYS.SYS_CONSTRAINT_DEFS C, SYS.SYS_TABLES T
  WHERE C.USER# = U.ID AND T.USER# = U.ID AND T.ID = C.TABLE# AND T.RECYCLED = 0 AND C.CONS_TYPE = 3
    AND (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM DB_CONSTRAINTS FOR SYS.DB_CONSTRAINTS
/
GRANT SELECT ON DB_CONSTRAINTS TO PUBLIC
/
CREATE OR REPLACE VIEW MY_CONSTRAINTS
(
  OWNER,
  CONSTRAINT_NAME,
  CONSTRAINT_TYPE,
  TABLE_NAME,
  SEARCH_CONDITION,
  R_OWNER,
  R_TABLE_NAME,
  R_CONSTRAINT_NAME,
  DELETE_RULE,
  STATUS,
  DEFERRABLE,
  DEFERRED,
  VALIDATED,
  BAD,
  RELY,
  INDEX_OWNER,
  INDEX_NAME,
  INVALID,
  VIEW_RELATED,
  CONS_COLS,
  REF_COLS,
  SYS_GENERATE,
  IS_DUPLICATE
)
AS
  SELECT M.USER_NAME, C.CONS_NAME, 'R', T.NAME, C.COND_TEXT, U.NAME, T2.NAME, I.NAME,
    DECODE(C.REFACT, 1, 'DELETE CASCADE', 2, 'SET NULL', 'NOT ALLOWED') DELETE_RULE, DECODE(C.FLAGS & 2, 2, 'ENABLED', 'DISABLED'), 'NOT DEFERRABLE', 'IMMEDIATE', DECODE(C.FLAGS & 4, 4, 'VALIDATED', 'NOT VALIDATED'), '', '', '', '', 'FALSE', '',
    DBE_DIAGNOSE.DBA_LISTCOLS(M.USER_NAME, '"'||T.NAME||'"', C.COL_LIST) CONS_COLS, DBE_DIAGNOSE.DBA_LISTCOLS(U2.NAME, '"'||T2.NAME||'"', I.COL_LIST) REF_COLS, DECODE(C.FLAGS & 8, 8, 'Y', 'N') SYS_GENERATE, DECODE(C.FLAGS & 1024, 0, 'N', 'Y') IS_DUPLICATE 
  FROM SYS.DV_ME M, SYS.SYS_USERS U, SYS.SYS_CONSTRAINT_DEFS C, SYS.SYS_TABLES T, SYS.SYS_INDEXES I, SYS.SYS_USERS U2, SYS.SYS_TABLES T2
  WHERE C.USER# = M.USER_ID AND T.USER# = M.USER_ID AND T.ID = C.TABLE# AND T.RECYCLED = 0 AND C.REF_USER# = I.USER# AND C.REF_TABLE# = I.TABLE# AND C.REF_CONS = I.ID AND C.REF_USER# = U.ID
    AND I.USER# = U2.ID AND I.TABLE# = T2.ID AND I.USER# = T2.USER# AND C.CONS_TYPE = 2
    AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT M.USER_NAME, C.CONS_NAME, DECODE(C.CONS_TYPE, 0, 'P', 1, 'U', ''), T.NAME, C.COND_TEXT, '', '', '',
    '', DECODE(C.FLAGS & 2, 2, 'ENABLED', 'DISABLED'), 'NOT DEFERRABLE', 'IMMEDIATE', DECODE(C.FLAGS & 4, 4, 'VALIDATED', 'NOT VALIDATED'), '', '', M.USER_NAME, I.NAME, 'FALSE', '',
    DBE_DIAGNOSE.DBA_LISTCOLS(M.USER_NAME, '"'||T.NAME||'"', C.COL_LIST) CONS_COLS, '' REF_COLS, DECODE(C.FLAGS & 8, 8, 'Y', 'N') SYS_GENERATE, DECODE(C.FLAGS & 1024, 0, 'N', 'Y') IS_DUPLICATE 
  FROM SYS.DV_ME M, SYS.SYS_CONSTRAINT_DEFS C, SYS.SYS_TABLES T, SYS.SYS_INDEXES I
  WHERE C.USER# = M.USER_ID AND T.USER# = M.USER_ID AND T.ID = C.TABLE#
    AND C.COL_LIST = I.COL_LIST AND C.USER# = I.USER# AND C.TABLE# = I.TABLE# AND T.RECYCLED = 0 AND (C.CONS_TYPE = 0 OR C.CONS_TYPE = 1)
  UNION ALL
  SELECT M.USER_NAME, C.CONS_NAME, 'C',  T.NAME, C.COND_TEXT, '', '', '',
    '', DECODE(C.FLAGS & 2, 2, 'ENABLED', 'DISABLED'), 'NOT DEFERRABLE', 'IMMEDIATE', DECODE(C.FLAGS & 4, 4, 'VALIDATED', 'NOT VALIDATED'), '', '', '', '', 'FALSE', '', DBE_DIAGNOSE.DBA_LISTCOLS(M.USER_NAME,'"'||T.NAME||'"', C.COL_LIST) CONS_COLS,'' REF_COLS, DECODE(C.FLAGS & 8, 8, 'Y', 'N') SYS_GENERATE, DECODE(C.FLAGS & 1024, 0, 'N', 'Y') IS_DUPLICATE
  FROM SYS.DV_ME M, SYS.SYS_CONSTRAINT_DEFS C, SYS.SYS_TABLES T
  WHERE C.USER# = M.USER_ID AND T.USER# = M.USER_ID AND T.ID = C.TABLE# AND T.RECYCLED = 0 AND C.CONS_TYPE = 3
/
CREATE OR REPLACE PUBLIC SYNONYM MY_CONSTRAINTS FOR SYS.MY_CONSTRAINTS
/
GRANT SELECT ON MY_CONSTRAINTS TO PUBLIC
/
--28
CREATE OR REPLACE VIEW MY_CONS_COLUMNS
(
  OWNER,
  CONSTRAINT_NAME,
  TABLE_NAME,
  COLUMN_NAME,
  POSITION
) 
AS 
  SELECT M.USER_NAME, CON.CONS_NAME, T.NAME, C.NAME, CEIL(LOCATE(C.ID, ','||CON.COL_LIST)/2) 
  FROM SYS.DV_ME M, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.SYS_CONSTRAINT_DEFS CON
  WHERE CON.USER# = M.USER_ID AND CON.USER# = C.USER# AND CON.USER# = T.USER# AND CON.TABLE# = C.TABLE#  AND CON.TABLE# = T.ID AND CON.TABLE# = C.TABLE# AND T.RECYCLED = 0 AND LOCATE(CONCAT(',',C.ID,','), CONCAT(',',CON.COL_LIST,',')) > 0
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_CONS_COLUMNS        FOR SYS.MY_CONS_COLUMNS 
/
GRANT SELECT ON MY_CONS_COLUMNS TO PUBLIC
/

CREATE OR REPLACE VIEW DB_CONS_COLUMNS
(
  OWNER,
  CONSTRAINT_NAME,
  TABLE_NAME,
  COLUMN_NAME,
  POSITION
) 
AS 
  SELECT U.NAME, CON.CONS_NAME, T.NAME, C.NAME, CEIL(LOCATE(C.ID, ','||CON.COL_LIST)/2) 
  FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.SYS_CONSTRAINT_DEFS CON
  WHERE CON.USER# = U.ID AND CON.USER# = C.USER# AND CON.USER# = T.USER# AND CON.TABLE# = C.TABLE#  AND CON.TABLE# = T.ID AND CON.TABLE# = C.TABLE# AND T.RECYCLED = 0 AND LOCATE(CONCAT(',',C.ID,','), CONCAT(',',CON.COL_LIST,',')) > 0 and 
        (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_CONS_COLUMNS      FOR SYS.DB_CONS_COLUMNS
/
GRANT SELECT ON DB_CONS_COLUMNS TO PUBLIC
/
--29
CREATE OR REPLACE VIEW DB_TRIGGERS
(
  OWNER,
  TRIGGER_NAME,
  TABLE_OWNER,
  TABLE_NAME,
  SOURCE,
  STATUS
)
AS
	SELECT U.NAME, P.NAME, P.TRIG_TABLE_USER, P.TRIG_TABLE, P.SOURCE, P.TRIG_STATUS FROM SYS.SYS_USERS U, SYS.SYS_PROCS P 
    WHERE P.TYPE = 'T' AND P.USER# = U.ID
        and (U.NAME = user or 
             user = 'SYS' or 
             DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||P.NAME||'"', P.TYPE)) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_TRIGGERS     FOR SYS.DB_TRIGGERS
/
GRANT SELECT ON DB_TRIGGERS TO PUBLIC
/
CREATE OR REPLACE VIEW ADM_TRIGGERS
(
  OWNER,
  TRIGGER_NAME,
  TABLE_OWNER,
  TABLE_NAME,
  SOURCE,
  STATUS
)
AS
	SELECT U.NAME, P.NAME, P.TRIG_TABLE_USER, P.TRIG_TABLE, P.SOURCE, P.TRIG_STATUS FROM SYS.SYS_USERS U, SYS.SYS_PROCS P WHERE P.TYPE = 'T' AND P.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_TRIGGERS      FOR SYS.ADM_TRIGGERS
/
CREATE OR REPLACE VIEW MY_TRIGGERS
(
  TRIGGER_NAME,
  TABLE_OWNER,
  TABLE_NAME,
  SOURCE,
  STATUS
)
AS
	SELECT P.NAME, P.TRIG_TABLE_USER, P.TRIG_TABLE, P.SOURCE, P.TRIG_STATUS FROM SYS.DV_ME M, SYS.SYS_PROCS P WHERE P.TYPE = 'T' AND P.USER# = M.USER_ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_TRIGGERS     FOR SYS.MY_TRIGGERS
/
GRANT SELECT ON MY_TRIGGERS TO PUBLIC
/
--30
CREATE OR REPLACE VIEW ADM_ROLES
(
  ROLE,
  PASSWORD_REQUIRED,
  AUTHENTICATION_TYPE
)
AS
  SELECT R.NAME, 'NO', 'PASSWORD' FROM SYS.SYS_ROLES R
/
CREATE OR REPLACE PUBLIC SYNONYM ADM_ROLES FOR SYS.ADM_ROLES
/
CREATE OR REPLACE VIEW ADM_ARGUMENTS
(
  OWNER,
  OBJECT_NAME,
  PACKAGE_NAME,
  OVERLOAD,
  SUBPROGRAM_ID,
  ARGUMENT_NAME,
  POSITION,
  SEQUENCE,
  DATA_LEVEL,
  DATA_TYPE,
  DEFAULTED,
  DEFAULT_VALUE,
  IN_OUT,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE
)
AS
  SELECT U.NAME, A.OBJECT_NAME, A.PACKAGE, DECODE(A.OVERLOAD, 0, NULL, TO_CHAR(A.OVERLOAD)),PROC_SEQ, 
         A.ARGUMENT_NAME, A.POSITION,A.SEQUENCE,A.DATA_LEVEL, 
         TYPE_ID2NAME(A.DATA_TYPE),
         DECODE(A.DEFAULTED, 0,'N', 1,'Y'),
         A.DEFAULT_VALUE,
         DECODE(A.IN_OUT, 2,'OUT',3,'IN OUT','IN'),
         A.DATA_LENGTH,
         A.DATA_PRECISION,
         A.DATA_SCALE FROM SYS.SYS_USERS U, SYS.SYS_PROC_ARGS A WHERE U.ID = A.USER# AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_ARGUMENTS      FOR SYS.ADM_ARGUMENTS
/

CREATE OR REPLACE VIEW DB_ARGUMENTS
(
  OWNER,
  OBJECT_NAME,
  PACKAGE_NAME,
  OVERLOAD,
  SUBPROGRAM_ID,
  ARGUMENT_NAME,
  POSITION,
  SEQUENCE,
  DATA_LEVEL,
  DATA_TYPE,
  DEFAULTED,
  DEFAULT_VALUE,
  IN_OUT,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE
)
AS
  SELECT U.NAME, A.OBJECT_NAME, A.PACKAGE, DECODE(A.OVERLOAD, 0, NULL, TO_CHAR(A.OVERLOAD)),PROC_SEQ, 
         A.ARGUMENT_NAME, A.POSITION,A.SEQUENCE,A.DATA_LEVEL, 
         TYPE_ID2NAME(A.DATA_TYPE),
         DECODE(A.DEFAULTED, 0,'N', 1,'Y'),
         A.DEFAULT_VALUE,
         DECODE(A.IN_OUT, 2,'OUT',3,'IN OUT','IN'),
         A.DATA_LENGTH,
         A.DATA_PRECISION,
         A.DATA_SCALE FROM SYS.SYS_USERS U, SYS.SYS_PROC_ARGS A, SYS.SYS_PROCS P 
  WHERE U.ID = A.USER# and
        U.ID = P.USER# and
        P.NAME = A.OBJECT_NAME and  
        (P.TYPE <> 'S' and P.TYPE <> 'B') and
        (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||P.NAME||'"', P.TYPE)) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL  
  SELECT U.NAME, A.OBJECT_NAME, A.PACKAGE, DECODE(A.OVERLOAD, 0, NULL, TO_CHAR(A.OVERLOAD)),PROC_SEQ, 
         A.ARGUMENT_NAME, A.POSITION,A.SEQUENCE,A.DATA_LEVEL, 
         TYPE_ID2NAME(A.DATA_TYPE),
         DECODE(A.DEFAULTED, 0,'N', 1,'Y'),
         A.DEFAULT_VALUE,
         DECODE(A.IN_OUT, 2,'OUT',3,'IN OUT','IN'),
         A.DATA_LENGTH,
         A.DATA_PRECISION,
         A.DATA_SCALE FROM SYS.SYS_USERS U, SYS.SYS_PROC_ARGS A, SYS.SYS_PROCS P 
  WHERE U.ID = A.USER# and
        U.ID = P.USER# and  
        P.NAME = A.PACKAGE and
        P.USER# = A.USER# and               
        P.TYPE = 'S' and
        (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||P.NAME||'"', 'PACKAGE')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_ARGUMENTS     FOR SYS.DB_ARGUMENTS
/
GRANT SELECT ON DB_ARGUMENTS TO PUBLIC
/

CREATE OR REPLACE VIEW MY_ARGUMENTS
(
  OBJECT_NAME,
  PACKAGE_NAME,
  OVERLOAD,
  SUBPROGRAM_ID,
  ARGUMENT_NAME,
  POSITION,
  SEQUENCE,
  DATA_LEVEL,
  DATA_TYPE,
  DEFAULTED,
  DEFAULT_VALUE,
  IN_OUT,
  DATA_LENGTH,
  DATA_PRECISION,
  DATA_SCALE
)
AS
  SELECT A.OBJECT_NAME, A.PACKAGE, DECODE(A.OVERLOAD, 0, NULL, TO_CHAR(A.OVERLOAD)),PROC_SEQ, 
         A.ARGUMENT_NAME, A.POSITION,A.SEQUENCE,A.DATA_LEVEL, 
         TYPE_ID2NAME(A.DATA_TYPE),
         DECODE(A.DEFAULTED, 0,'N', 1,'Y'),
         A.DEFAULT_VALUE,
         DECODE(A.IN_OUT, 2,'OUT',3,'IN OUT','IN'),
         A.DATA_LENGTH,
         A.DATA_PRECISION,
         A.DATA_SCALE FROM SYS.DV_ME M, SYS.SYS_PROC_ARGS A WHERE M.USER_ID = A.USER#
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_ARGUMENTS     FOR SYS.MY_ARGUMENTS
/
GRANT SELECT ON MY_ARGUMENTS TO PUBLIC
/
--31
CREATE OR REPLACE VIEW DB_TAB_STATISTICS
(
  OWNER,
  TABLE_NAME,
  PARTITION_NAME,
  PARTITION_POSITION,
  OBJECT_TYPE,
  NUM_ROWS,
  BLOCKS,
  EMPTY_BLOCKS,
  AVG_SPACE,
  CHAIN_CNT,
  AVG_ROW_LEN,
  AVG_SPACE_FREELIST_BLOCKS,
  NUM_FREELIST_BLOCKS,
  AVG_CACHED_BLOCKS,
  AVG_CACHE_HIT_RATIO,
  SAMPLE_SIZE,
  LAST_ANALYZED
)
AS
  SELECT U.NAME, T.NAME, NULL::VARCHAR(64), NULL::NUMBER, 
  'TABLE', T.NUM_ROWS, T.BLOCKS, T.EMPTY_BLOCKS,
  NULL::NUMBER, NULL::NUMBER, T.AVG_ROW_LEN, 
  NULL::NUMBER, NULL::NUMBER, NULL::NUMBER, NULL::NUMBER, T.SAMPLESIZE, T.ANALYZETIME
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  where T.RECYCLED = 0 AND
        (U.NAME = user or 
         user = 'SYS' or 
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
  UNION ALL
  SELECT U.NAME, T.NAME, TP.NAME, ROW_NUMBER() OVER (PARTITION BY TP.USER#, TP.TABLE# ORDER BY TP.PART#), 
  'PARTITION', TP.ROWCNT, TP.BLKCNT, TP.EMPCNT,
  NULL::NUMBER, NULL::NUMBER, TP.AVGRLN,
  NULL::NUMBER, NULL::NUMBER, NULL::NUMBER, NULL::NUMBER, TP.SAMPLESIZE, TP.ANALYZETIME
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_TABLE_PARTS TP ON T.USER# = TP.USER# AND T.ID = TP.TABLE#
  where T.RECYCLED = 0 AND
       (U.NAME = user or 
         user = 'SYS' or 
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
  UNION ALL
  SELECT U.NAME, T.NAME, TSUBP.NAME, ROW_NUMBER() OVER (PARTITION BY TSUBP.USER#, TSUBP.TABLE#, TSUBP.PARENT_PART# ORDER BY TSUBP.SUBPART#), 
  'SUBPARTITION', TSUBP.ROWCNT, TSUBP.BLKCNT, TSUBP.EMPCNT,
  NULL::NUMBER, NULL::NUMBER, TSUBP.AVGRLN,
  NULL::NUMBER, NULL::NUMBER, NULL::NUMBER, NULL::NUMBER, TSUBP.SAMPLESIZE, TSUBP.ANALYZETIME
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_SUB_TABLE_PARTS TSUBP ON T.USER# = TSUBP.USER# AND T.ID = TSUBP.TABLE#
  where T.RECYCLED = 0 AND
       (U.NAME = user or 
         user = 'SYS' or 
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
/

CREATE OR REPLACE VIEW ADM_TAB_STATISTICS
(
  OWNER,
  TABLE_NAME,
  PARTITION_NAME,
  PARTITION_POSITION,
  OBJECT_TYPE,
  NUM_ROWS,
  BLOCKS,
  EMPTY_BLOCKS,
  AVG_SPACE,
  CHAIN_CNT,
  AVG_ROW_LEN,
  AVG_SPACE_FREELIST_BLOCKS,
  NUM_FREELIST_BLOCKS,
  AVG_CACHED_BLOCKS,
  AVG_CACHE_HIT_RATIO,
  SAMPLE_SIZE,
  LAST_ANALYZED
)
AS
  SELECT * FROM SYS.DB_TAB_STATISTICS
/

CREATE OR REPLACE VIEW MY_TAB_STATISTICS
(
  TABLE_NAME,
  PARTITION_NAME,
  PARTITION_POSITION,
  OBJECT_TYPE,
  NUM_ROWS,
  BLOCKS,
  EMPTY_BLOCKS,
  AVG_SPACE,
  CHAIN_CNT,
  AVG_ROW_LEN,
  AVG_SPACE_FREELIST_BLOCKS,
  NUM_FREELIST_BLOCKS,
  AVG_CACHED_BLOCKS,
  AVG_CACHE_HIT_RATIO,
  SAMPLE_SIZE,
  LAST_ANALYZED
)
AS
  SELECT T.NAME, NULL::VARCHAR(64), NULL::NUMBER, 
  'TABLE', T.NUM_ROWS, T.BLOCKS, T.EMPTY_BLOCKS,
  NULL::NUMBER, NULL::NUMBER, T.AVG_ROW_LEN, 
  NULL::NUMBER, NULL::NUMBER, NULL::NUMBER, NULL::NUMBER, T.SAMPLESIZE, T.ANALYZETIME
  FROM SYS.DV_ME M JOIN SYS.SYS_TABLES T ON T.USER# = M.USER_ID
  UNION ALL
  SELECT T.NAME, TP.NAME, ROW_NUMBER() OVER (PARTITION BY TP.USER#, TP.TABLE# ORDER BY TP.PART#), 
  'PARTITION', TP.ROWCNT, TP.BLKCNT, TP.EMPCNT,
  NULL::NUMBER, NULL::NUMBER, TP.AVGRLN,
  NULL::NUMBER, NULL::NUMBER, NULL::NUMBER, NULL::NUMBER, TP.SAMPLESIZE, TP.ANALYZETIME
  FROM SYS.DV_ME M JOIN SYS.SYS_TABLES T ON T.USER# = M.USER_ID
  JOIN SYS.SYS_TABLE_PARTS TP ON T.USER# = TP.USER# AND T.ID = TP.TABLE#
  UNION ALL
  SELECT T.NAME, TSUBP.NAME, ROW_NUMBER() OVER (PARTITION BY TSUBP.USER#, TSUBP.TABLE#, TSUBP.PARENT_PART# ORDER BY TSUBP.SUBPART#), 
  'SUBPARTITION', TSUBP.ROWCNT, TSUBP.BLKCNT, TSUBP.EMPCNT,
  NULL::NUMBER, NULL::NUMBER, TSUBP.AVGRLN,
  NULL::NUMBER, NULL::NUMBER, NULL::NUMBER, NULL::NUMBER, TSUBP.SAMPLESIZE, TSUBP.ANALYZETIME
  FROM SYS.DV_ME M JOIN SYS.SYS_TABLES T ON T.USER# = M.USER_ID
  JOIN SYS.SYS_SUB_TABLE_PARTS TSUBP ON T.USER# = TSUBP.USER# AND T.ID = TSUBP.TABLE#
/

CREATE OR REPLACE PUBLIC SYNONYM  DB_TAB_STATISTICS     FOR SYS.DB_TAB_STATISTICS
/
GRANT SELECT ON DB_TAB_STATISTICS TO PUBLIC
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_TAB_STATISTICS     FOR SYS.ADM_TAB_STATISTICS
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_TAB_STATISTICS    FOR SYS.MY_TAB_STATISTICS
/
GRANT SELECT ON MY_TAB_STATISTICS TO PUBLIC
/
--32
CREATE OR REPLACE VIEW DB_IND_PARTITIONS
(
  INDEX_OWNER,
  INDEX_NAME,
  COMPOSITE,
  PARTITION_NAME,
  PARTITION_POSITION,
  STATUS,
  PCT_FREE,
  INI_TRANS,
  MAX_TRANS,
  BLEVEL,
  LEAF_BLOCKS,
  DISTINCT_KEYS,
  AVG_LEAF_BLOCKS_PER_KEY,
  AVG_DATA_BLOCKS_PER_KEY,
  CLUSTERING_FACTOR,
  NUM_ROWS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  TABLESPACE_NAME
)
AS
  SELECT U.NAME, I.NAME, DECODE(IP.FLAGS & 0x40, 0, 'NO', 'YES'), IP.NAME,
  TP.PART#,
  DECODE(IP.FLAGS & 4, 0, 'VALID', 'INVALID'), IP.PCTFREE, IP.INITRANS, 255,
  IP.BLEVEL, IP.LEVEL_BLOCKS, IP.DISTKEY, IP.LBLKKEY, IP.DBLKKEY, IP.CLUFAC,
  TP.ROWCNT, IP.SAMPLESIZE, IP.ANALYZETIME, TS.NAME
  FROM SYS.SYS_USERS U  
  JOIN SYS.SYS_TABLE_PARTS TP ON TP.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_TABLES T ON T.ID = TP.TABLE# AND T.USER# = U.ID
  JOIN SYS.SYS_INDEX_PARTS IP ON TP.USER# = IP.USER# AND TP.TABLE# = IP.TABLE# AND TP.PART#=IP.PART#
  JOIN SYS.SYS_INDEXES I ON IP.USER# = I.USER# AND IP.TABLE# = I.TABLE# AND IP.INDEX# = I.ID
  JOIN SYS.DV_TABLESPACES TS ON TS.ID = IP.SPACE#
  where T.RECYCLED = 0 AND
       (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
/

CREATE OR REPLACE VIEW ADM_IND_PARTITIONS
(
  INDEX_OWNER,
  INDEX_NAME,
  COMPOSITE,
  PARTITION_NAME,
  PARTITION_POSITION,
  STATUS,
  PCT_FREE,
  INI_TRANS,
  MAX_TRANS,
  BLEVEL,
  LEAF_BLOCKS,
  DISTINCT_KEYS,
  AVG_LEAF_BLOCKS_PER_KEY,
  AVG_DATA_BLOCKS_PER_KEY,
  CLUSTERING_FACTOR,
  NUM_ROWS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  TABLESPACE_NAME
)
AS
  SELECT U.NAME, I.NAME, DECODE(IP.FLAGS & 0x40, 0, 'NO', 'YES'), IP.NAME,
  TP.PART#,
  DECODE(IP.FLAGS & 4, 0, 'VALID', 'INVALID'), IP.PCTFREE, IP.INITRANS, 255,
  IP.BLEVEL, IP.LEVEL_BLOCKS, IP.DISTKEY, IP.LBLKKEY, IP.DBLKKEY, IP.CLUFAC,
  TP.ROWCNT, IP.SAMPLESIZE, IP.ANALYZETIME, TS.NAME
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLE_PARTS TP ON TP.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_INDEX_PARTS IP ON TP.USER# = IP.USER# AND TP.TABLE# = IP.TABLE# AND TP.PART#=IP.PART#
  JOIN SYS.SYS_INDEXES I ON IP.USER# = I.USER# AND IP.TABLE# = I.TABLE# AND IP.INDEX# = I.ID
  JOIN SYS.DV_TABLESPACES TS ON TS.ID = IP.SPACE#
/

CREATE OR REPLACE VIEW MY_IND_PARTITIONS
(
  INDEX_NAME,
  COMPOSITE,
  PARTITION_NAME,
  PARTITION_POSITION,
  STATUS,
  PCT_FREE,
  INI_TRANS,
  MAX_TRANS,
  BLEVEL,
  LEAF_BLOCKS,
  DISTINCT_KEYS,
  AVG_LEAF_BLOCKS_PER_KEY,
  AVG_DATA_BLOCKS_PER_KEY,
  CLUSTERING_FACTOR,
  NUM_ROWS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  TABLESPACE_NAME
)
AS
  SELECT I.NAME, DECODE(IP.FLAGS & 0x40, 0, 'NO', 'YES'), IP.NAME,
  TP.PART#,
  DECODE(IP.FLAGS & 4, 0, 'VALID', 'INVALID'), IP.PCTFREE, IP.INITRANS, 255,
  IP.BLEVEL, IP.LEVEL_BLOCKS, IP.DISTKEY, IP.LBLKKEY, IP.DBLKKEY, IP.CLUFAC,
  TP.ROWCNT, IP.SAMPLESIZE, IP.ANALYZETIME, TS.NAME
  FROM SYS.DV_ME M JOIN SYS.SYS_TABLE_PARTS TP ON TP.USER# = M.USER_ID
  JOIN SYS.SYS_INDEX_PARTS IP ON TP.USER# = IP.USER# AND TP.TABLE# = IP.TABLE# AND TP.PART#=IP.PART#
  JOIN SYS.SYS_INDEXES I ON IP.USER# = I.USER# AND IP.TABLE# = I.TABLE# AND IP.INDEX# = I.ID
  JOIN SYS.DV_TABLESPACES TS ON TS.ID = IP.SPACE#
/

CREATE OR REPLACE PUBLIC SYNONYM  DB_IND_PARTITIONS     FOR SYS.DB_IND_PARTITIONS
/
GRANT SELECT ON DB_IND_PARTITIONS TO PUBLIC
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_IND_PARTITIONS     FOR SYS.ADM_IND_PARTITIONS
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_IND_PARTITIONS    FOR SYS.MY_IND_PARTITIONS
/
GRANT SELECT ON MY_IND_PARTITIONS TO PUBLIC
/

CREATE OR REPLACE VIEW DB_IND_SUBPARTITIONS
(
  INDEX_OWNER,
  INDEX_NAME,
  PARENTPART_NAME,
  PARTITION_NAME,
  PARTITION_POSITION,
  STATUS,
  PCT_FREE,
  INI_TRANS,
  MAX_TRANS,
  BLEVEL,
  LEAF_BLOCKS,
  DISTINCT_KEYS,
  AVG_LEAF_BLOCKS_PER_KEY,
  AVG_DATA_BLOCKS_PER_KEY,
  CLUSTERING_FACTOR,
  NUM_ROWS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  TABLESPACE_NAME
)
AS
  SELECT U.NAME, I.NAME, IP.NAME, ISUBP.NAME,
  ROW_NUMBER() OVER (PARTITION BY ISUBP.USER#, ISUBP.TABLE#, ISUBP.INDEX#, ISUBP.PARENT_PART# ORDER BY ISUBP.SUBPART#),
  DECODE(ISUBP.FLAGS & 4, 0, 'VALID', 'INVALID'), ISUBP.PCTFREE, ISUBP.INITRANS, 255,
  ISUBP.BLEVEL, ISUBP.LEVEL_BLOCKS, ISUBP.DISTKEY, ISUBP.LBLKKEY, ISUBP.DBLKKEY, ISUBP.CLUFAC,
  TSUBP.ROWCNT, ISUBP.SAMPLESIZE, ISUBP.ANALYZETIME, TS.NAME
  FROM SYS.SYS_USERS U  
  JOIN SYS.SYS_SUB_TABLE_PARTS TSUBP ON TSUBP.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_TABLES T ON T.ID = TSUBP.TABLE# AND T.USER# = U.ID
  JOIN SYS.SYS_SUB_INDEX_PARTS ISUBP ON TSUBP.USER# = ISUBP.USER# AND TSUBP.TABLE# = ISUBP.TABLE# AND TSUBP.PARENT_PART# = ISUBP.PARENT_PART# AND TSUBP.SUBPART# = ISUBP.SUBPART#
  JOIN SYS.SYS_INDEX_PARTS IP ON IP.USER# = ISUBP.USER# AND IP.TABLE# = ISUBP.TABLE# AND IP.INDEX# = ISUBP.INDEX# AND IP.PART# = ISUBP.PARENT_PART# AND (IP.FLAGS & 0x64)
  JOIN SYS.SYS_INDEXES I ON ISUBP.USER# = I.USER# AND ISUBP.TABLE# = I.TABLE# AND ISUBP.INDEX# = I.ID
  JOIN SYS.DV_TABLESPACES TS ON TS.ID = ISUBP.SPACE#
  where T.RECYCLED = 0 AND
       (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
/

CREATE OR REPLACE VIEW ADM_IND_SUBPARTITIONS
(
  INDEX_OWNER,
  INDEX_NAME,
  PARENTPART_NAME,
  PARTITION_NAME,
  PARTITION_POSITION,
  STATUS,
  PCT_FREE,
  INI_TRANS,
  MAX_TRANS,
  BLEVEL,
  LEAF_BLOCKS,
  DISTINCT_KEYS,
  AVG_LEAF_BLOCKS_PER_KEY,
  AVG_DATA_BLOCKS_PER_KEY,
  CLUSTERING_FACTOR,
  NUM_ROWS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  TABLESPACE_NAME
)
AS
  SELECT U.NAME, I.NAME, IP.NAME, ISUBP.NAME,
  ROW_NUMBER() OVER (PARTITION BY ISUBP.USER#, ISUBP.TABLE#, ISUBP.INDEX#, ISUBP.PARENT_PART# ORDER BY ISUBP.SUBPART#),
  DECODE(ISUBP.FLAGS & 4, 0, 'VALID', 'INVALID'), ISUBP.PCTFREE, ISUBP.INITRANS, 255,
  ISUBP.BLEVEL, ISUBP.LEVEL_BLOCKS, ISUBP.DISTKEY, ISUBP.LBLKKEY, ISUBP.DBLKKEY, ISUBP.CLUFAC,
  TSUBP.ROWCNT, ISUBP.SAMPLESIZE, ISUBP.ANALYZETIME, TS.NAME
  FROM SYS.SYS_USERS U  
  JOIN SYS.SYS_SUB_TABLE_PARTS TSUBP ON TSUBP.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_SUB_INDEX_PARTS ISUBP ON TSUBP.USER# = ISUBP.USER# AND TSUBP.TABLE# = ISUBP.TABLE# AND TSUBP.PARENT_PART# = ISUBP.PARENT_PART# AND TSUBP.SUBPART# = ISUBP.SUBPART#
  JOIN SYS.SYS_INDEX_PARTS IP ON IP.USER# = ISUBP.USER# AND IP.TABLE# = ISUBP.TABLE# AND IP.INDEX# = ISUBP.INDEX# AND IP.PART# = ISUBP.PARENT_PART# AND (IP.FLAGS & 0x64)
  JOIN SYS.SYS_INDEXES I ON ISUBP.USER# = I.USER# AND ISUBP.TABLE# = I.TABLE# AND ISUBP.INDEX# = I.ID
  JOIN SYS.DV_TABLESPACES TS ON TS.ID = ISUBP.SPACE#
/

CREATE OR REPLACE VIEW MY_IND_SUBPARTITIONS
(
  INDEX_NAME,
  PARENTPART_NAME,
  PARTITION_NAME,
  PARTITION_POSITION,
  STATUS,
  PCT_FREE,
  INI_TRANS,
  MAX_TRANS,
  BLEVEL,
  LEAF_BLOCKS,
  DISTINCT_KEYS,
  AVG_LEAF_BLOCKS_PER_KEY,
  AVG_DATA_BLOCKS_PER_KEY,
  CLUSTERING_FACTOR,
  NUM_ROWS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  TABLESPACE_NAME
)
AS
  SELECT I.NAME, IP.NAME, ISUBP.NAME,
  ROW_NUMBER() OVER (PARTITION BY ISUBP.USER#, ISUBP.TABLE#, ISUBP.INDEX#, ISUBP.PARENT_PART# ORDER BY ISUBP.SUBPART#),
  DECODE(ISUBP.FLAGS & 4, 0, 'VALID', 'INVALID'), ISUBP.PCTFREE, ISUBP.INITRANS, 255,
  ISUBP.BLEVEL, ISUBP.LEVEL_BLOCKS, ISUBP.DISTKEY, ISUBP.LBLKKEY, ISUBP.DBLKKEY, ISUBP.CLUFAC,
  TSUBP.ROWCNT, ISUBP.SAMPLESIZE, ISUBP.ANALYZETIME, TS.NAME
  FROM SYS.DV_ME M 
  JOIN SYS.SYS_SUB_TABLE_PARTS TSUBP ON TSUBP.USER# = M.USER_ID
  JOIN SYS.SYS_SUB_INDEX_PARTS ISUBP ON TSUBP.USER# = ISUBP.USER# AND TSUBP.TABLE# = ISUBP.TABLE# AND TSUBP.PARENT_PART# = ISUBP.PARENT_PART# AND TSUBP.SUBPART# = ISUBP.SUBPART#
  JOIN SYS.SYS_INDEX_PARTS IP ON IP.USER# = ISUBP.USER# AND IP.TABLE# = ISUBP.TABLE# AND IP.INDEX# = ISUBP.INDEX# AND IP.PART# = ISUBP.PARENT_PART# AND (IP.FLAGS & 0x64)
  JOIN SYS.SYS_INDEXES I ON ISUBP.USER# = I.USER# AND ISUBP.TABLE# = I.TABLE# AND ISUBP.INDEX# = I.ID
  JOIN SYS.DV_TABLESPACES TS ON TS.ID = ISUBP.SPACE#
/

CREATE OR REPLACE PUBLIC SYNONYM  DB_IND_SUBPARTITIONS     FOR SYS.DB_IND_SUBPARTITIONS
/
GRANT SELECT ON DB_IND_SUBPARTITIONS TO PUBLIC
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_IND_SUBPARTITIONS     FOR SYS.ADM_IND_SUBPARTITIONS
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_IND_SUBPARTITIONS    FOR SYS.MY_IND_SUBPARTITIONS
/
GRANT SELECT ON MY_IND_SUBPARTITIONS TO PUBLIC
/
--33
CREATE OR REPLACE VIEW DB_IND_STATISTICS
(
  OWNER,
  INDEX_NAME,
  TABLE_OWNER,
  TABLE_NAME,
  PARTITION_NAME,
  PARTITION_POSITION,
  OBJECT_TYPE,
  BLEVEL,
  LEAF_BLOCKS,
  DISTINCT_KEYS,
  AVG_LEAF_BLOCKS_PER_KEY,
  AVG_DATA_BLOCKS_PER_KEY,
  CLUSTERING_FACTOR,
  NUM_ROWS,
  SAMPLE_SIZE,
  LAST_ANALYZED
)
AS
  SELECT U.NAME, I.NAME, U.NAME, T.NAME, NULL::VARCHAR(64), NULL::NUMBER,
         'INDEX', I.BLEVEL, I.LEVEL_BLOCKS, I.DISTINCT_KEYS, I.AVG_LEAF_BLOCKS_PER_KEY, I.AVG_DATA_BLOCKS_PER_KEY,
         I.CLUFAC, T.NUM_ROWS, T.SAMPLESIZE, T.ANALYZETIME
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_INDEXES I ON T.USER# = I.USER# AND T.ID = I.TABLE# 
  where T.RECYCLED = 0 AND
       (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
  UNION ALL
  SELECT U.NAME, I.NAME, U.NAME, T.NAME, TP.NAME,
         ROW_NUMBER() OVER (PARTITION BY TP.USER#, TP.TABLE# ORDER BY TP.PART#),
         'PARTITION', IP.BLEVEL, IP.LEVEL_BLOCKS, IP.DISTKEY, IP.LBLKKEY, IP.DBLKKEY,
         NULL::NUMBER, TP.ROWCNT, IP.SAMPLESIZE, IP.ANALYZETIME
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_INDEXES I ON T.USER# = I.USER# AND T.ID = I.TABLE#
  JOIN SYS.SYS_TABLE_PARTS TP ON T.USER# = TP.USER# AND T.ID = TP.TABLE# 
  JOIN SYS.SYS_INDEX_PARTS IP ON I.USER# = IP.USER# AND I.TABLE# = IP.TABLE# AND I.ID = IP.INDEX# AND TP.PART# = IP.PART#
  where T.RECYCLED = 0 AND
       (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
  UNION ALL
  SELECT U.NAME, I.NAME, U.NAME, T.NAME, ISUBP.NAME,
         ROW_NUMBER() OVER (PARTITION BY ISUBP.USER#, ISUBP.TABLE#, ISUBP.INDEX#, ISUBP.PARENT_PART# ORDER BY ISUBP.SUBPART#),
         'SUBPARTITION', ISUBP.BLEVEL, ISUBP.LEVEL_BLOCKS, ISUBP.DISTKEY, ISUBP.LBLKKEY, ISUBP.DBLKKEY,
         NULL::NUMBER, TSUBP.ROWCNT, ISUBP.SAMPLESIZE, ISUBP.ANALYZETIME
  FROM SYS.SYS_USERS U 
  JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_INDEXES I ON T.USER# = I.USER# AND T.ID = I.TABLE#
  JOIN SYS.SYS_SUB_TABLE_PARTS TSUBP ON T.USER# = TSUBP.USER# AND T.ID = TSUBP.TABLE# 
  JOIN SYS.SYS_SUB_INDEX_PARTS ISUBP ON I.USER# = ISUBP.USER# AND I.TABLE# = ISUBP.TABLE# AND I.ID = ISUBP.INDEX# AND TSUBP.PARENT_PART# = ISUBP.PARENT_PART# AND TSUBP.SUBPART# = ISUBP.SUBPART#
  where T.RECYCLED = 0 AND
       (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
/

CREATE OR REPLACE VIEW ADM_IND_STATISTICS
(
  OWNER,
  INDEX_NAME,
  TABLE_OWNER,
  TABLE_NAME,
  PARTITION_NAME,
  PARTITION_POSITION,
  OBJECT_TYPE,
  BLEVEL,
  LEAF_BLOCKS,
  DISTINCT_KEYS,
  AVG_LEAF_BLOCKS_PER_KEY,
  AVG_DATA_BLOCKS_PER_KEY,
  CLUSTERING_FACTOR,
  NUM_ROWS,
  SAMPLE_SIZE,
  LAST_ANALYZED
)
AS
  SELECT U.NAME, I.NAME, U.NAME, T.NAME, NULL::VARCHAR(64), NULL::NUMBER,
         'INDEX', I.BLEVEL, I.LEVEL_BLOCKS, I.DISTINCT_KEYS, I.AVG_LEAF_BLOCKS_PER_KEY, I.AVG_DATA_BLOCKS_PER_KEY,
         I.CLUFAC, T.NUM_ROWS, I.SAMPLESIZE, I.ANALYZETIME
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_INDEXES I ON T.USER# = I.USER# AND T.ID = I.TABLE# 
  UNION ALL
  SELECT U.NAME, I.NAME, U.NAME, T.NAME, TP.NAME,
         ROW_NUMBER() OVER (PARTITION BY TP.USER#, TP.TABLE# ORDER BY TP.PART#),
         'PARTITION', IP.BLEVEL, IP.LEVEL_BLOCKS, IP.DISTKEY, IP.LBLKKEY, IP.DBLKKEY,
         NULL::NUMBER, TP.ROWCNT, IP.SAMPLESIZE, IP.ANALYZETIME
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_INDEXES I ON T.USER# = I.USER# AND T.ID = I.TABLE#
  JOIN SYS.SYS_TABLE_PARTS TP ON T.USER# = TP.USER# AND T.ID = TP.TABLE# 
  JOIN SYS.SYS_INDEX_PARTS IP ON I.USER# = IP.USER# AND I.TABLE# = IP.TABLE# AND I.ID = IP.INDEX# AND TP.PART# = IP.PART#
  UNION ALL
  SELECT U.NAME, I.NAME, U.NAME, T.NAME, ISUBP.NAME,
         ROW_NUMBER() OVER (PARTITION BY ISUBP.USER#, ISUBP.TABLE#, ISUBP.INDEX#, ISUBP.PARENT_PART# ORDER BY ISUBP.SUBPART#),
         'SUBPARTITION', ISUBP.BLEVEL, ISUBP.LEVEL_BLOCKS, ISUBP.DISTKEY, ISUBP.LBLKKEY, ISUBP.DBLKKEY,
         NULL::NUMBER, TSUBP.ROWCNT, ISUBP.SAMPLESIZE, ISUBP.ANALYZETIME
  FROM SYS.SYS_USERS U 
  JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_INDEXES I ON T.USER# = I.USER# AND T.ID = I.TABLE#
  JOIN SYS.SYS_SUB_TABLE_PARTS TSUBP ON T.USER# = TSUBP.USER# AND T.ID = TSUBP.TABLE# 
  JOIN SYS.SYS_SUB_INDEX_PARTS ISUBP ON I.USER# = ISUBP.USER# AND I.TABLE# = ISUBP.TABLE# AND I.ID = ISUBP.INDEX# AND TSUBP.PARENT_PART# = ISUBP.PARENT_PART# AND TSUBP.SUBPART# = ISUBP.SUBPART#
/

CREATE OR REPLACE VIEW MY_IND_STATISTICS
(
  INDEX_NAME,
  TABLE_OWNER,
  TABLE_NAME,
  PARTITION_NAME,
  PARTITION_POSITION,
  OBJECT_TYPE,
  BLEVEL,
  LEAF_BLOCKS,
  DISTINCT_KEYS,
  AVG_LEAF_BLOCKS_PER_KEY,
  AVG_DATA_BLOCKS_PER_KEY,
  CLUSTERING_FACTOR,
  NUM_ROWS,
  SAMPLE_SIZE,
  LAST_ANALYZED
)
AS
  SELECT I.NAME, M.USER_NAME, T.NAME, NULL::VARCHAR(64), NULL::NUMBER,
         'INDEX', I.BLEVEL, I.LEVEL_BLOCKS, I.DISTINCT_KEYS, I.AVG_LEAF_BLOCKS_PER_KEY, I.AVG_DATA_BLOCKS_PER_KEY,
         I.CLUFAC, T.NUM_ROWS, T.SAMPLESIZE, T.ANALYZETIME
  FROM SYS.DV_ME M JOIN SYS.SYS_TABLES T ON T.USER# = M.USER_ID
  JOIN SYS.SYS_INDEXES I ON T.USER# = I.USER# AND T.ID = I.TABLE#
  UNION ALL
  SELECT I.NAME, M.USER_NAME, T.NAME, TP.NAME,
         ROW_NUMBER() OVER (PARTITION BY TP.USER#, TP.TABLE# ORDER BY TP.PART#),
         'PARTITION', IP.BLEVEL, IP.LEVEL_BLOCKS, IP.DISTKEY, IP.LBLKKEY, IP.DBLKKEY,
         NULL::NUMBER, TP.ROWCNT, IP.SAMPLESIZE, IP.ANALYZETIME
  FROM SYS.DV_ME M JOIN SYS.SYS_TABLES T ON T.USER# = M.USER_ID
  JOIN SYS.SYS_INDEXES I ON T.USER# = I.USER# AND T.ID = I.TABLE#
  JOIN SYS.SYS_TABLE_PARTS TP ON T.USER# = TP.USER# AND T.ID = TP.TABLE# 
  JOIN SYS.SYS_INDEX_PARTS IP ON I.USER# = IP.USER# AND I.TABLE# = IP.TABLE# AND I.ID = IP.INDEX# AND TP.PART# = IP.PART#
  UNION ALL
  SELECT I.NAME, M.USER_NAME, T.NAME, ISUBP.NAME,
         ROW_NUMBER() OVER (PARTITION BY ISUBP.USER#, ISUBP.TABLE#, ISUBP.INDEX#, ISUBP.PARENT_PART# ORDER BY ISUBP.SUBPART#),
         'SUBPARTITION', ISUBP.BLEVEL, ISUBP.LEVEL_BLOCKS, ISUBP.DISTKEY, ISUBP.LBLKKEY, ISUBP.DBLKKEY,
         NULL::NUMBER, TSUBP.ROWCNT, ISUBP.SAMPLESIZE, ISUBP.ANALYZETIME
  FROM SYS.DV_ME M 
  JOIN SYS.SYS_TABLES T ON T.USER# = M.USER_ID
  JOIN SYS.SYS_INDEXES I ON T.USER# = I.USER# AND T.ID = I.TABLE#
  JOIN SYS.SYS_SUB_TABLE_PARTS TSUBP ON T.USER# = TSUBP.USER# AND T.ID = TSUBP.TABLE# 
  JOIN SYS.SYS_SUB_INDEX_PARTS ISUBP ON I.USER# = ISUBP.USER# AND I.TABLE# = ISUBP.TABLE# AND I.ID = ISUBP.INDEX# AND TSUBP.PARENT_PART# = ISUBP.PARENT_PART# AND TSUBP.SUBPART# = ISUBP.SUBPART#
/

CREATE OR REPLACE PUBLIC SYNONYM  DB_IND_STATISTICS     FOR SYS.DB_IND_STATISTICS
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_IND_STATISTICS     FOR SYS.ADM_IND_STATISTICS
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_IND_STATISTICS    FOR SYS.MY_IND_STATISTICS
/
GRANT SELECT ON MY_IND_STATISTICS TO PUBLIC
/

CREATE OR REPLACE VIEW DB_TAB_COL_STATISTICS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  DENSITY,
  NUM_NULLS,
  NUM_BUCKETS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  AVG_COL_LEN,
  HISTOGRAM
)
AS
  SELECT U.NAME, T.NAME, C.NAME, HH.DIST_NUM, HH.MINVALUE, HH.MAXVALUE, 
  HH.DENSITY, HH.NULL_NUM, HH.BUCKET_NUM, HH.SPARE3, HH.ANALYZE_TIME, NULL::NUMBER, C.HISTOGRAM
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_COLUMNS C ON T.ID = C.TABLE# AND T.USER# = C.USER#
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL#  AND (HH.SPARE1 IS NULL OR HH.SPARE1 = 4294967295)
  where T.RECYCLED = 0 AND
       (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE')) 
/

CREATE OR REPLACE VIEW ADM_TAB_COL_STATISTICS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  DENSITY,
  NUM_NULLS,
  NUM_BUCKETS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  AVG_COL_LEN,
  HISTOGRAM
)
AS
  SELECT U.NAME, T.NAME, C.NAME, HH.DIST_NUM, HH.MINVALUE, HH.MAXVALUE, 
  HH.DENSITY, HH.NULL_NUM, HH.BUCKET_NUM, HH.SPARE3, HH.ANALYZE_TIME, NULL::NUMBER, C.HISTOGRAM
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_COLUMNS C ON T.ID = C.TABLE# AND T.USER# = C.USER#
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL#  AND (HH.SPARE1 IS NULL OR HH.SPARE1 = 4294967295)
/

CREATE OR REPLACE VIEW MY_TAB_COL_STATISTICS
(
  TABLE_NAME,
  COLUMN_NAME,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  DENSITY,
  NUM_NULLS,
  NUM_BUCKETS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  AVG_COL_LEN,
  HISTOGRAM
)
AS
  SELECT T.NAME, C.NAME, HH.DIST_NUM, HH.MINVALUE, HH.MAXVALUE, 
  HH.DENSITY, HH.NULL_NUM, HH.BUCKET_NUM, HH.SPARE3, HH.ANALYZE_TIME, NULL::NUMBER, C.HISTOGRAM
  FROM SYS.DV_ME M JOIN SYS.SYS_TABLES T ON T.USER# = M.USER_ID
  JOIN SYS.SYS_COLUMNS C ON T.ID = C.TABLE# AND T.USER# = C.USER#
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND (HH.SPARE1 IS NULL OR HH.SPARE1 = 4294967295)
/

CREATE OR REPLACE PUBLIC SYNONYM  DB_TAB_COL_STATISTICS     FOR SYS.DB_TAB_COL_STATISTICS
/
GRANT SELECT ON DB_TAB_COL_STATISTICS TO PUBLIC
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_TAB_COL_STATISTICS     FOR SYS.ADM_TAB_COL_STATISTICS
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_TAB_COL_STATISTICS    FOR SYS.MY_TAB_COL_STATISTICS
/
GRANT SELECT ON MY_TAB_COL_STATISTICS TO PUBLIC
/

CREATE OR REPLACE VIEW DB_PART_COL_STATISTICS
(
  OWNER,
  TABLE_NAME,
  PARTITION_NAME,
  COLUMN_NAME,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  DENSITY,
  NUM_NULLS,
  NUM_BUCKETS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  AVG_COL_LEN,
  HISTOGRAM
)
AS
  SELECT U.NAME, T.NAME, TP.NAME, C.NAME, HH.DIST_NUM, HH.MINVALUE, HH.MAXVALUE,
  HH.DENSITY, HH.NULL_NUM, HH.BUCKET_NUM, HH.SPARE3, HH.ANALYZE_TIME, NULL::NUMBER, C.HISTOGRAM
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_TABLE_PARTS TP ON T.USER# = TP.USER# AND T.ID = TP.TABLE#  
  JOIN SYS.SYS_COLUMNS C ON TP.USER# = C.USER# AND TP.TABLE# = C.TABLE# 
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND HH.SPARE1 = TP.PART#
  where T.RECYCLED = 0 AND
       (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))

/

CREATE OR REPLACE VIEW ADM_PART_COL_STATISTICS
(
  OWNER,
  TABLE_NAME,
  PARTITION_NAME,
  COLUMN_NAME,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  DENSITY,
  NUM_NULLS,
  NUM_BUCKETS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  AVG_COL_LEN,
  HISTOGRAM
)
AS
  SELECT U.NAME, T.NAME, TP.NAME, C.NAME, HH.DIST_NUM, HH.MINVALUE, HH.MAXVALUE, 
  HH.DENSITY, HH.NULL_NUM, HH.BUCKET_NUM, HH.SPARE3, HH.ANALYZE_TIME, NULL::NUMBER, C.HISTOGRAM
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_TABLE_PARTS TP ON T.USER# = TP.USER# AND T.ID = TP.TABLE#  
  JOIN SYS.SYS_COLUMNS C ON TP.USER# = C.USER# AND TP.TABLE# = C.TABLE# 
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND HH.SPARE1 = TP.PART#
/

CREATE OR REPLACE VIEW MY_PART_COL_STATISTICS
(
  TABLE_NAME,
  PARTITION_NAME,
  COLUMN_NAME,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  DENSITY,
  NUM_NULLS,
  NUM_BUCKETS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  AVG_COL_LEN,
  HISTOGRAM
)
AS
  SELECT T.NAME, TP.NAME, C.NAME, HH.DIST_NUM, HH.MINVALUE, HH.MAXVALUE, 
  HH.DENSITY, HH.NULL_NUM, HH.BUCKET_NUM, HH.SPARE3, HH.ANALYZE_TIME, NULL::NUMBER, C.HISTOGRAM
  FROM SYS.DV_ME M JOIN SYS.SYS_TABLES T ON T.USER# = M.USER_ID
  JOIN SYS.SYS_TABLE_PARTS TP ON T.USER# = TP.USER# AND T.ID = TP.TABLE#  
  JOIN SYS.SYS_COLUMNS C ON TP.USER# = C.USER# AND TP.TABLE# = C.TABLE#
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND HH.SPARE1 = TP.PART#
/

CREATE OR REPLACE PUBLIC SYNONYM  DB_PART_COL_STATISTICS     FOR SYS.DB_PART_COL_STATISTICS
/
GRANT SELECT ON DB_PART_COL_STATISTICS TO PUBLIC
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_PART_COL_STATISTICS     FOR SYS.ADM_PART_COL_STATISTICS
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_PART_COL_STATISTICS    FOR SYS.MY_PART_COL_STATISTICS
/
GRANT SELECT ON MY_PART_COL_STATISTICS TO PUBLIC
/

CREATE OR REPLACE VIEW DB_SUBPART_COL_STATISTICS
(
  OWNER,
  TABLE_NAME,
  PARTITION_NAME,
  COLUMN_NAME,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  DENSITY,
  NUM_NULLS,
  NUM_BUCKETS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  AVG_COL_LEN,
  HISTOGRAM
)
AS
  SELECT U.NAME, T.NAME, TSUBP.NAME, C.NAME, HH.DIST_NUM, HH.MINVALUE, HH.MAXVALUE,
  HH.DENSITY, HH.NULL_NUM, HH.BUCKET_NUM, HH.SPARE3, HH.ANALYZE_TIME, NULL::NUMBER, C.HISTOGRAM
  FROM SYS.SYS_USERS U 
  JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_SUB_TABLE_PARTS TSUBP ON T.USER# = TSUBP.USER# AND T.ID = TSUBP.TABLE#  
  JOIN SYS.SYS_COLUMNS C ON TSUBP.USER# = C.USER# AND TSUBP.TABLE# = C.TABLE# 
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND HH.SPARE1 = TSUBP.PARENT_PART# AND HH.SPARE2 = TSUBP.SUBPART#
  where T.RECYCLED = 0 AND
       (U.NAME = user or 
         user = 'SYS' or
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))

/

CREATE OR REPLACE VIEW ADM_SUBPART_COL_STATISTICS
(
  OWNER,
  TABLE_NAME,
  PARTITION_NAME,
  COLUMN_NAME,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  DENSITY,
  NUM_NULLS,
  NUM_BUCKETS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  AVG_COL_LEN,
  HISTOGRAM
)
AS
  SELECT U.NAME, T.NAME, TSUBP.NAME, C.NAME, HH.DIST_NUM, HH.MINVALUE, HH.MAXVALUE, 
  HH.DENSITY, HH.NULL_NUM, HH.BUCKET_NUM, HH.SPARE3, HH.ANALYZE_TIME, NULL::NUMBER, C.HISTOGRAM
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_SUB_TABLE_PARTS TSUBP ON T.USER# = TSUBP.USER# AND T.ID = TSUBP.TABLE#  
  JOIN SYS.SYS_COLUMNS C ON TSUBP.USER# = C.USER# AND TSUBP.TABLE# = C.TABLE# 
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND HH.SPARE1 = TSUBP.PARENT_PART# AND HH.SPARE2 = TSUBP.SUBPART#
/

CREATE OR REPLACE VIEW MY_SUBPART_COL_STATISTICS
(
  TABLE_NAME,
  PARTITION_NAME,
  COLUMN_NAME,
  NUM_DISTINCT,
  LOW_VALUE,
  HIGH_VALUE,
  DENSITY,
  NUM_NULLS,
  NUM_BUCKETS,
  SAMPLE_SIZE,
  LAST_ANALYZED,
  AVG_COL_LEN,
  HISTOGRAM
)
AS
  SELECT T.NAME, TSUBP.NAME, C.NAME, HH.DIST_NUM, HH.MINVALUE, HH.MAXVALUE, 
  HH.DENSITY, HH.NULL_NUM, HH.BUCKET_NUM, HH.SPARE3, HH.ANALYZE_TIME, NULL::NUMBER, C.HISTOGRAM
  FROM SYS.DV_ME M 
  JOIN SYS.SYS_TABLES T ON T.USER# = M.USER_ID
  JOIN SYS.SYS_SUB_TABLE_PARTS TSUBP ON T.USER# = TSUBP.USER# AND T.ID = TSUBP.TABLE#  
  JOIN SYS.SYS_COLUMNS C ON TSUBP.USER# = C.USER# AND TSUBP.TABLE# = C.TABLE#
  LEFT JOIN SYS.SYS_HISTGRAM_ABSTR HH ON C.USER# = HH.USER# AND C.TABLE# = HH.TAB# AND C.ID = HH.COL# AND HH.SPARE1 = TSUBP.PARENT_PART# AND HH.SPARE2 = TSUBP.SUBPART#
/

CREATE OR REPLACE PUBLIC SYNONYM  DB_SUBPART_COL_STATISTICS     FOR SYS.DB_SUBPART_COL_STATISTICS
/
GRANT SELECT ON DB_SUBPART_COL_STATISTICS TO PUBLIC
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_SUBPART_COL_STATISTICS     FOR SYS.ADM_SUBPART_COL_STATISTICS
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_SUBPART_COL_STATISTICS    FOR SYS.MY_SUBPART_COL_STATISTICS
/
GRANT SELECT ON MY_SUBPART_COL_STATISTICS TO PUBLIC
/
--34
CREATE OR REPLACE VIEW DB_HISTOGRAMS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  ENDPOINT_NUMBER,
  ENDPOINT_VALUE,
  ENDPOINT_ACTUAL_VALUE
)
AS
  SELECT U.NAME, T.NAME, C.NAME, ROW_NUMBER() OVER (PARTITION BY T.NAME, C.NAME ORDER BY H.ENDPOINT), H.ENDPOINT, H.BUCKET
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_COLUMNS C ON T.USER# = C.USER# AND T.ID = C.TABLE# 
  JOIN SYS.SYS_HISTGRAM H ON C.USER# = H.USER# AND C.TABLE# = H.TABLE# AND C.ID = H.COL# AND (H.PART# IS NULL OR H.PART# = -1)
  WHERE T.RECYCLED = 0 AND
        (U.NAME = user OR 
         user = 'SYS' OR
         DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||T.NAME||'"', 'TABLE'))
/

CREATE OR REPLACE VIEW ADM_HISTOGRAMS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  ENDPOINT_NUMBER,
  ENDPOINT_VALUE,
  ENDPOINT_ACTUAL_VALUE
)
AS
  SELECT U.NAME, T.NAME, C.NAME, ROW_NUMBER() OVER (PARTITION BY T.NAME, C.NAME ORDER BY H.ENDPOINT), H.ENDPOINT, H.BUCKET
  FROM SYS.SYS_USERS U JOIN SYS.SYS_TABLES T ON T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  JOIN SYS.SYS_COLUMNS C ON T.USER# = C.USER# AND T.ID = C.TABLE# 
  JOIN SYS.SYS_HISTGRAM H ON C.USER# = H.USER# AND C.TABLE# = H.TABLE# AND C.ID = H.COL# AND (H.PART# IS NULL OR H.PART# = -1)
/

CREATE OR REPLACE VIEW MY_HISTOGRAMS
(
  TABLE_NAME,
  COLUMN_NAME,
  ENDPOINT_NUMBER,
  ENDPOINT_VALUE,
  ENDPOINT_ACTUAL_VALUE
)
AS
  SELECT T.NAME, C.NAME, ROW_NUMBER() OVER (PARTITION BY T.NAME, C.NAME ORDER BY H.ENDPOINT), H.ENDPOINT, H.BUCKET
  FROM SYS.DV_ME M JOIN SYS.SYS_TABLES T ON T.USER# = M.USER_ID 
  JOIN SYS.SYS_COLUMNS C ON T.USER# = C.USER# AND T.ID = C.TABLE# 
  JOIN SYS.SYS_HISTGRAM H ON C.USER# = H.USER# AND C.TABLE# = H.TABLE# AND C.ID = H.COL# AND (H.PART# IS NULL OR H.PART# = -1)
/

CREATE OR REPLACE VIEW SYS.ADM_DB_LINKS
(
  OWNER,
  DB_LINK,
  USERNAME,
  HOST,
  CREATED
)
AS
  SELECT U.NAME, L.NAME, L.USERID, L.HOST, L.CTIME 
  FROM SYS.SYS_LINKS L, SYS.SYS_USERS U 
  WHERE L.OWNER# = U.ID AND 
        DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/ 

CREATE OR REPLACE VIEW SYS.DB_DB_LINKS
(
  OWNER,
  DB_LINK,
  USERNAME,
  HOST,
  CREATED
)
AS
  SELECT M.USER_NAME, L.NAME, L.USERID, L.HOST, L.CTIME 
  FROM SYS.SYS_LINKS L, SYS.DV_ME M
  WHERE L.OWNER# = M.USER_ID
/ 

CREATE OR REPLACE VIEW SYS.MY_DB_LINKS
(
  DB_LINK,
  USERNAME,
  HOST,
  CREATED
)
AS
  SELECT L.NAME, L.USERID, L.HOST, L.CTIME 
  FROM SYS.SYS_LINKS L, SYS.DV_ME M
  WHERE L.OWNER# = M.USER_ID
/ 
CREATE OR REPLACE PUBLIC SYNONYM  ADM_DB_LINKS      FOR SYS.ADM_DB_LINKS
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_DB_LINKS      FOR SYS.DB_DB_LINKS
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_DB_LINKS     FOR SYS.MY_DB_LINKS
/
GRANT SELECT ON DB_DB_LINKS TO PUBLIC
/
GRANT SELECT ON MY_DB_LINKS TO PUBLIC
/
CREATE OR REPLACE VIEW SYS.DB_JOBS AS
SELECT JOB, LOWNER LOG_USER, POWNER PRIV_USER, COWNER SCHEMA_USER,
    LAST_DATE, SUBSTR(TO_CHAR(LAST_DATE,'HH24:MI:SS'),1,8) LAST_SEC,
    THIS_DATE, SUBSTR(TO_CHAR(THIS_DATE,'HH24:MI:SS'),1,8) THIS_SEC,
    NEXT_DATE, SUBSTR(TO_CHAR(NEXT_DATE,'HH24:MI:SS'),1,8) NEXT_SEC,
    DECODE(MOD(BROKEN,2),1,'Y',0,'N','?') BROKEN,
    INTERVAL# INTERVAL_TIME, FAILURES,
	  WHAT, CREATE_DATE
  FROM SYS.SYS_JOBS J
/
CREATE OR REPLACE VIEW SYS.ADM_JOBS AS
SELECT JOB, LOWNER LOG_USER, POWNER PRIV_USER, COWNER SCHEMA_USER,
    LAST_DATE, SUBSTR(TO_CHAR(LAST_DATE,'HH24:MI:SS'),1,8) LAST_SEC,
    THIS_DATE, SUBSTR(TO_CHAR(THIS_DATE,'HH24:MI:SS'),1,8) THIS_SEC,
    NEXT_DATE, SUBSTR(TO_CHAR(NEXT_DATE,'HH24:MI:SS'),1,8) NEXT_SEC,
    DECODE(MOD(BROKEN,2),1,'Y',0,'N','?') BROKEN,
    INTERVAL# INTERVAL_TIME, FAILURES,
	WHAT, CREATE_DATE
  FROM SYS.SYS_JOBS J
/

CREATE OR REPLACE VIEW SYS.MY_JOBS AS
SELECT 
	J.JOB,J.LOG_USER,J.PRIV_USER,J.SCHEMA_USER,J.LAST_DATE,J.LAST_SEC,
	J.THIS_DATE,J.THIS_SEC,J.NEXT_DATE,J.NEXT_SEC,J.BROKEN,J.INTERVAL_TIME, FAILURES,
	J.WHAT,CREATE_DATE
FROM ADM_JOBS J, SYS.DV_ME M WHERE
J.LOG_USER = M.USER_NAME
/

CREATE OR REPLACE VIEW SYS.ADM_JOBS_RUNNING AS
SELECT V.JOBNO JOB, V.SESSION_ID SID, V.SERIAL_ID SERIAL#, J.FAILURES,
    J.LAST_DATE, SUBSTR(TO_CHAR(J.LAST_DATE,'HH24:MI:SS'),1,8) LAST_SEC,
    J.THIS_DATE, SUBSTR(TO_CHAR(J.THIS_DATE,'HH24:MI:SS'),1,8) THIS_SEC
  FROM SYS.DV_RUNNING_JOBS V LEFT JOIN SYS.SYS_JOBS J ON V.JOBNO = J.JOB
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_JOBS        FOR SYS.DB_JOBS 
/  
CREATE OR REPLACE PUBLIC SYNONYM  ADM_JOBS        FOR SYS.ADM_JOBS 
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_JOBS        FOR SYS.MY_JOBS 
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_JOBS_RUNNING FOR SYS.ADM_JOBS_RUNNING
/
GRANT SELECT ON MY_JOBS TO PUBLIC
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_HISTOGRAMS     FOR SYS.DB_HISTOGRAMS
/
GRANT SELECT ON DB_HISTOGRAMS TO PUBLIC
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_HISTOGRAMS     FOR SYS.ADM_HISTOGRAMS
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_HISTOGRAMS    FOR SYS.MY_HISTOGRAMS
/
GRANT SELECT ON MY_HISTOGRAMS TO PUBLIC
/

--35
CREATE OR REPLACE VIEW SYS.DB_DEPENDENCIES
(OWNER, NAME, TYPE, REFERENCED_OWNER, REFERENCED_NAME, REFERENCED_TYPE)
AS
SELECT DBE_DIAGNOSE.DBA_USER_NAME(D_OWNER#)::VARCHAR(64), D.D_NAME,
       DECODE(D.D_TYPE#, 0, 'TABLE', 1, 'VIEW', 2, 'SEQUENCE', 3, 'PROCEDURE',
                      7, 'SYNONYM', 8, 'FUNCTION', 9, 'TRIGGER', 10, 'INDEX',
                      11, 'DYNAMIC VIEW',15,'SYNONYM', 16, 'PACKAGE', 17 , 'PACKAGE BODY', 19, 'TYPE', 30, 'SYS_PACKAGE', 'UNDEFINED'),
       DBE_DIAGNOSE.DBA_USER_NAME(P_OWNER#)::VARCHAR(64), D.P_NAME,
       DECODE(D.P_TYPE#, 0, 'TABLE', 1, 'VIEW', 2, 'SEQUENCE', 3, 'PROCEDURE',
                      7, 'SYNONYM', 8, 'FUNCTION', 9, 'TRIGGER', 10, 'INDEX',
                      11, 'DYNAMIC VIEW',15,'SYNONYM', 16, 'PACKAGE', 17 , 'PACKAGE BODY', 19, 'TYPE', 30, 'SYS_PACKAGE', 'UNDEFINED')
FROM SYS.SYS_DEPENDENCIES D where DBE_DIAGNOSE.TENANT_CHECK(2, D_OWNER#) AND (DBE_DIAGNOSE.DBA_USER_NAME(D_OWNER#)::VARCHAR(64) = user or user = 'SYS' 
    or exists (select 1 from SYS.SYS_USER_ROLES S, SYS.DV_ME V where S.GRANTEE_ID = V.USER_ID and S.GRANTEE_TYPE = 0 and S.GRANTED_ROLE_ID = 0))
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_DEPENDENCIES       FOR SYS.DB_DEPENDENCIES 
/
GRANT SELECT ON DB_DEPENDENCIES TO PUBLIC
/

CREATE OR REPLACE VIEW SYS.DB_VIEW_DEPENDENCIES
(OWNER, NAME, REFERENCED_OWNER, REFERENCED_NAME, REFERENCED_LEVEL)
    AS
    SELECT 
        DBE_DIAGNOSE.DBA_USER_NAME(D_OWNER#)::VARCHAR(64) as OWNER, 
        D.D_NAME,
        DBE_DIAGNOSE.DBA_USER_NAME(P_OWNER#)::VARCHAR(64) as REFERENCED_OWNER, 
        D.P_NAME, 
        LEVEL REFERENCED_LEVEL
    FROM 
        SYS.SYS_DEPENDENCIES D WHERE DBE_DIAGNOSE.TENANT_CHECK(2, D_OWNER#)
    START WITH 
        D.D_TYPE# = 1 and D.P_TYPE# = 1 and (DBE_DIAGNOSE.DBA_USER_NAME(D_OWNER#)::VARCHAR(64) = user or user = 'SYS' 
    or exists (select 1 from SYS.SYS_USER_ROLES S, SYS.DV_ME V where S.GRANTEE_ID = V.USER_ID and S.GRANTEE_TYPE = 0 and S.GRANTED_ROLE_ID = 0))
    CONNECT BY 
        prior D.P_NAME = D.D_NAME and prior D.P_OWNER# = D.D_OWNER# and D.P_TYPE# = 1 and D.D_TYPE# = 1
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_VIEW_DEPENDENCIES   FOR SYS.DB_VIEW_DEPENDENCIES 
/
GRANT SELECT ON DB_VIEW_DEPENDENCIES TO PUBLIC
/

CREATE OR REPLACE VIEW SYS.ADM_DEPENDENCIES
(OWNER, NAME, TYPE, REFERENCED_OWNER, REFERENCED_NAME, REFERENCED_TYPE)
AS
SELECT DBE_DIAGNOSE.DBA_USER_NAME(D_OWNER#)::VARCHAR(64) as OWNER, D.D_NAME,
       DECODE(D.D_TYPE#, 0, 'TABLE', 1, 'VIEW', 2, 'SEQUENCE', 3, 'PROCEDURE',
                      7, 'SYNONYM', 8, 'FUNCTION', 9, 'TRIGGER', 10, 'INDEX',
                      11, 'DYNAMIC VIEW',15,'SYNONYM', 16, 'PACKAGE', 17 , 'PACKAGE BODY', 19, 'TYPE', 30, 'SYS_PACKAGE', 'UNDEFINED'),
       DBE_DIAGNOSE.DBA_USER_NAME(P_OWNER#)::VARCHAR(64), D.P_NAME,
       DECODE(D.P_TYPE#, 0, 'TABLE', 1, 'VIEW', 2, 'SEQUENCE', 3, 'PROCEDURE',
                      7, 'SYNONYM', 8, 'FUNCTION', 9, 'TRIGGER', 10, 'INDEX',
                      11, 'DYNAMIC VIEW',15,'SYNONYM', 16, 'PACKAGE', 17 , 'PACKAGE BODY', 19, 'TYPE', 30, 'SYS_PACKAGE', 'UNDEFINED')
FROM SYS.SYS_DEPENDENCIES D WHERE DBE_DIAGNOSE.TENANT_CHECK(2, D_OWNER#)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_DEPENDENCIES       FOR SYS.ADM_DEPENDENCIES 
/

CREATE OR REPLACE VIEW SYS.MY_DEPENDENCIES
(OWNER, NAME, TYPE, REFERENCED_OWNER, REFERENCED_NAME, REFERENCED_TYPE)
AS
SELECT DBE_DIAGNOSE.DBA_USER_NAME(D.D_OWNER#)::VARCHAR(64), D.D_NAME,
       DECODE(D.D_TYPE#, 0, 'TABLE', 1, 'VIEW', 2, 'SEQUENCE', 3, 'PROCEDURE',
                      7, 'SYNONYM', 8, 'FUNCTION', 9, 'TRIGGER', 10, 'INDEX',
                      11, 'DYNAMIC VIEW',15,'SYNONYM', 16, 'PACKAGE', 17 , 'PACKAGE BODY', 19, 'TYPE', 30, 'SYS_PACKAGE', 'UNDEFINED'),
       DBE_DIAGNOSE.DBA_USER_NAME(D.P_OWNER#)::VARCHAR(64), D.P_NAME,
       DECODE(D.P_TYPE#, 0, 'TABLE', 1, 'VIEW', 2, 'SEQUENCE', 3, 'PROCEDURE',
                      7, 'SYNONYM', 8, 'FUNCTION', 9, 'TRIGGER', 10, 'INDEX',
                      11, 'DYNAMIC VIEW',15,'SYNONYM', 16, 'PACKAGE', 17 , 'PACKAGE BODY', 19, 'TYPE', 30, 'SYS_PACKAGE', 'UNDEFINED')
FROM SYS.SYS_DEPENDENCIES D, SYS.DV_ME M
WHERE D.D_OWNER# = M.USER_ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_DEPENDENCIES       FOR SYS.MY_DEPENDENCIES 
/
GRANT SELECT ON MY_DEPENDENCIES TO PUBLIC
/
--36


CREATE OR REPLACE VIEW SYS.DB_DIRECTORIES
(
  USER#,
  DIRECTORY_NAME,
  DIRECTORY_PATH
)
AS
  SELECT D.* FROM SYS.SYS_USERS U, SYS.SYS_DIRECTORIES D
    WHERE U.ID = D.USER# and 
          (U.NAME = user or 
           user = 'SYS' or 
           DBE_DIAGNOSE.has_obj_privs(user, U.NAME, '"'||D.DIRECTORY_NAME||'"', 'DIRECTORY')) AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_DIRECTORIES FOR SYS.DB_DIRECTORIES
/
GRANT SELECT ON DB_DIRECTORIES TO PUBLIC
/

CREATE OR REPLACE VIEW ADM_RSRC_PLANS
(
  PLAN_ID,
  PLAN,
  NUM_PLAN_RULES,
  COMMENTS,
  TYPE#
)
AS
  SELECT * FROM SYS.SYS_RSRC_PLANS
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_RSRC_PLANS FOR SYS.ADM_RSRC_PLANS
/

CREATE OR REPLACE VIEW ADM_RSRC_CONTROL_GROUPS
(
  CONTROL_GROUP_ID,
  CONTROL_GROUP,
  COMMENTS
)
AS
  SELECT * FROM SYS.SYS_RSRC_CONTROL_GROUPS
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_RSRC_CONTROL_GROUPS FOR SYS.ADM_RSRC_CONTROL_GROUPS
/

CREATE OR REPLACE VIEW ADM_RSRC_GROUP_MAPPINGS
(
  ATTRIBUTE,
  VALUE,
  CONTROL_GROUP
)
AS
  SELECT * FROM SYS.SYS_RSRC_GROUP_MAPPINGS
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_RSRC_GROUP_MAPPINGS FOR SYS.ADM_RSRC_GROUP_MAPPINGS
/

CREATE OR REPLACE VIEW ADM_RSRC_PLAN_RULES
(
  PLAN,
  CONTROL_GROUP,
  CPU_LIMIT,
  MAX_SESSIONS,
  MAX_ACTIVE_SESSIONS,
  MAX_QUEUE_TIME,
  MAX_EXEC_TIME,
  TEMP_POOL,
  MAX_IOPS,
  MAX_COMMITS,
  COMMENTS
)
AS
  SELECT * FROM SYS.SYS_RSRC_PLAN_RULES
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_RSRC_PLAN_RULES FOR SYS.ADM_RSRC_PLAN_RULES
/
--38
CREATE OR REPLACE VIEW ADM_PL_MANAGER
( 
  USER_NAME, 
  NAME, 
  TYPE,
  PACKAGE_NAME
)
AS SELECT USER_NAME, NAME, TYPE, PACKAGE_NAME FROM SYS.DV_PL_MANAGER 
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_PL_MANAGER   FOR SYS.ADM_PL_MANAGER
/
CREATE OR REPLACE VIEW DB_PL_MANAGER
( 
  USER_NAME, 
  NAME, 
  TYPE,
  PACKAGE_NAME
)
AS SELECT USER_NAME, NAME, TYPE, PACKAGE_NAME 
FROM SYS.DV_PL_MANAGER 
where
USER_NAME = user or
user = 'SYS' or
exists (select 1 from SYS.SYS_USER_ROLES S, SYS.DV_ME V where S.GRANTEE_ID = V.USER_ID and S.GRANTEE_TYPE = 0 and S.GRANTED_ROLE_ID = 0)
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_PL_MANAGER   FOR SYS.DB_PL_MANAGER
/
GRANT SELECT ON  DB_PL_MANAGER TO PUBLIC
/

CREATE OR REPLACE VIEW MY_PL_MANAGER
( 
  USER_NAME, 
  NAME, 
  TYPE,
  PACKAGE_NAME
)
AS SELECT PLM.USER_NAME, PLM.NAME, PLM.TYPE, PLM.PACKAGE_NAME 
FROM SYS.DV_ME ME, SYS.DV_PL_MANAGER PLM
WHERE PLM.USER# = ME.USER_ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_PL_MANAGER   FOR SYS.MY_PL_MANAGER
/
GRANT SELECT ON  MY_PL_MANAGER TO PUBLIC
/
--39
CREATE OR REPLACE VIEW MY_PACKAGES
(
  USER_NAME,
  PACKAGE_NAME,
  OBJECT_NAME, 
  OBJECT_TYPE
)
AS SELECT PLM.USER_NAME, PLM.PACKAGE_NAME, PLM.NAME, PLM.TYPE 
FROM SYS.DV_ME ME, SYS.DV_PL_MANAGER PLM, SYS.SYS_PROCS PRO
WHERE PLM.USER# = ME.USER_ID AND PLM.USER# = PRO.USER# AND PLM.PACKAGE_NAME = PRO.NAME AND PRO.TYPE = 'S' 
ORDER BY PRO.USER#, PRO.NAME;
/


CREATE OR REPLACE VIEW ADM_PACKAGES
(
  USER_NAME,
  PACKAGE_NAME,
  OBJECT_NAME, 
  OBJECT_TYPE
)
AS SELECT PLM.USER_NAME, PLM.PACKAGE_NAME, PLM.NAME, PLM.TYPE 
FROM SYS.DV_PL_MANAGER PLM, SYS.SYS_PROCS PRO
WHERE PLM.USER# = PRO.USER# AND PLM.PACKAGE_NAME = PRO.NAME AND PRO.TYPE = 'S'
ORDER BY PRO.USER#, PRO.NAME;
/

CREATE OR REPLACE VIEW DB_PACKAGES
(
  USER_NAME,
  PACKAGE_NAME,
  OBJECT_NAME, 
  OBJECT_TYPE
)
AS SELECT PLM.USER_NAME, PLM.PACKAGE_NAME, PLM.NAME, PLM.TYPE
FROM SYS.DV_PL_MANAGER PLM, SYS.SYS_PROCS PRO
WHERE PLM.USER# = PRO.USER# AND PLM.PACKAGE_NAME = PRO.NAME AND PRO.TYPE = 'S' 
AND (USER_NAME = user or user = 'SYS' or DBE_DIAGNOSE.has_obj_privs(user, USER_NAME, '"'||PRO.NAME||'"', 'PACKAGE'))
ORDER BY PRO.USER#, PRO.NAME;
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_PACKAGES   FOR SYS.MY_PACKAGES
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_PACKAGES   FOR SYS.ADM_PACKAGES
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_PACKAGES   FOR SYS.DB_PACKAGES
/
GRANT SELECT ON  MY_PACKAGES TO PUBLIC
/
GRANT SELECT ON  DB_PACKAGES TO PUBLIC
/

--40
CREATE OR REPLACE VIEW DB_ROLLBACK_STATUS
(
ROLLBACK_STATUS,
REMAINED
)
AS
  SELECT *
  FROM (SELECT IF(COUNT(*)>0, 'TRUE','FALSE') STA,
        COUNT(*) as STATUS FROM SYS.DV_TRANSACTIONS as T WHERE T.REMAINED = 'TRUE' and T.STATUS = 'ACTIVE' group by REMAINED
		HAVING COUNT(*) > 0 UNION ALL SELECT 'FALSE',0)
  ORDER BY STA DESC
  LIMIT 1;
/
CREATE OR REPLACE PUBLIC SYNONYM  DB_ROLLBACK_STATUS FOR SYS.DB_ROLLBACK_STATUS
/
GRANT SELECT ON DB_ROLLBACK_STATUS TO PUBLIC
/
--41
CREATE OR REPLACE VIEW SYS.ROLE_SYS_PRIVS
(
  ROLE,
  PRIVILEGE,
  ADMIN_OPTION
)
AS
  SELECT R.NAME,
  DECODE(P.PRIVILEGE,
  1, 'ALTER ANY INDEX',
  2, 'ALTER ANY MATERIALIZED VIEW',
  3, 'ALTER ANY PROCEDURE',
  4, 'ALTER ANY ROLE',
  5, 'ALTER ANY SEQUENCE',
  6, 'ALTER ANY TABLE',
  7, 'ALTER ANY TRIGGER',
  8, 'ALTER DATABASE',
  9, 'ALTER PROFILE',
  10, 'ALTER SESSION',
  11, 'ALTER SYSTEM',
  12, 'ALTER TABLESPACE',
  13, 'ALTER USER',
  14, 'CREATE ANY INDEX',
  15, 'CREATE ANY MATERIALIZED VIEW',
  16, 'CREATE ANY PROCEDURE',
  17, 'CREATE ANY SEQUENCE',
  18, 'CREATE ANY SYNONYM',
  19, 'CREATE ANY TABLE',
  20, 'CREATE ANY TRIGGER',
  21, 'CREATE ANY VIEW',
  22, 'CREATE DATABASE',
  23, 'CREATE MATERIALIZED VIEW',
  24, 'CREATE NODE',
  25, 'CREATE PROCEDURE',
  26, 'CREATE PROFILE',
  27, 'CREATE PUBLIC SYNONYM',
  28, 'CREATE ROLE',
  29, 'CREATE SEQUENCE',
  30, 'CREATE SESSION',
  31, 'CREATE SYNONYM',
  32, 'CREATE TABLE',
  33, 'CREATE TABLESPACE',
  34, 'CREATE TRIGGER',
  35, 'CREATE USER',
  36, 'CREATE VIEW',
  38, 'DROP ANY INDEX',
  39, 'DROP ANY MATERIALIZED VIEW',
  40, 'DROP ANY PROCEDURE',
  41, 'DROP ANY ROLE',
  42, 'DROP ANY SEQUENCE',
  43, 'DROP ANY SYNONYM',
  44, 'DROP ANY TABLE',
  45, 'DROP ANY TRIGGER',
  46, 'DROP ANY VIEW',
  47, 'DROP PROFILE',
  48, 'DROP PUBLIC SYNONYM',
  49, 'DROP TABLESPACE',
  50, 'DROP USER',
  51, 'FLASHBACK ANY TABLE',
  52, 'FLASHBACK ARCHIVE ADMINISTER',
  53, 'GLOBAL QUERY REWRITE',
  54, 'GRANT ANY OBJECT PRIVILEGE',
  55, 'GRANT ANY PRIVILEGE',
  56, 'GRANT ANY ROLE',
  57, 'LOCK ANY TABLE',
  58, 'MANAGE TABLESPACE',
  59, 'ON COMMIT REFRESH',
  60, 'PURGE DBA_RECYCLEBIN',
  61, 'READ ANY TABLE',
  62, 'SELECT ANY SEQUENCE',
  63, 'SELECT ANY TABLE',
  64, 'UNLIMITED TABLESPACE',
  65, 'UNDER ANY VIEW',
  66, 'COMMENT ANY TABLE',
  67, 'UPDATE ANY TABLE',
  68, 'INSERT ANY TABLE',
  69, 'DELETE ANY TABLE',
  70, 'EXECUTE ANY PROCEDURE',
  71, 'SYSBACKUP',
  72, 'SYSDBA',
  73, 'SYSOPER',
  74, 'ANALYZE ANY',
  75, 'DROP NODE',
  76, 'ALTER NODE',
  78, 'CREATE ANY DIRECTORY',
  79, 'DROP ANY DIRECTORY',
  81, 'CREATE ANY SQL MAP',
  82, 'DROP ANY SQL MAP',
  83, 'CREATE ANY TYPE',
  84, 'CREATE TYPE',
  85, 'DROP ANY TYPE',
  86, 'EXECUTE ANY TYPE',
  87, 'CREATE CTRLFILE',
  88, 'CREATE LIBRARY',
  89, 'EXEMPT REDACTION POLICY',
  90, 'CREATE ANY LIBRARY',
  91, 'DROP ANY LIBRARY',
  92, 'EXECUTE ANY LIBRARY', 
  93, 'EXEMPT ACCESS POLICY',
  94, 'INHERIT ANY PRIVILEGES',
  95, 'CREATE TENANT',
  96, 'ALTER TENANT',
  97, 'DROP TENANT',
  98, 'SELECT ANY DICTIONARY',
  99, 'FORCE ANY TRANSACTION',
  100, 'CREATE DATABASE LINK',
  101, 'ALTER DATABASE LINK',
  102, 'DROP DATABASE LINK',
  103, 'USE ANY TABLESPACE',
  'UNKNOWN'),
  DECODE(P.ADMIN_OPTION, 0, 'NO', 'YES')
  FROM SYS.SYS_ROLES R INNER JOIN SYS.SYS_PRIVS P ON R.ID = P.GRANTEE_ID AND P.GRANTEE_TYPE = 1 where user = 'SYS' or exists (select * from SYS.SYS_USER_ROLES U, SYS.DV_ME V where U.GRANTEE_ID = V.USER_ID and U.GRANTEE_TYPE = 0 and (U.GRANTED_ROLE_ID = 0 or U.GRANTED_ROLE_ID = R.ID))
/
CREATE OR REPLACE PUBLIC SYNONYM  ROLE_SYS_PRIVS FOR SYS.ROLE_SYS_PRIVS
/
GRANT SELECT ON ROLE_SYS_PRIVS TO PUBLIC
/
--42
CREATE OR REPLACE VIEW  ADM_FOREIGN_DEPENDENCY 
(
  CHILD_OWNER,
  CHILD_TABLE,
  CHILD_COLS,
  CHILD_CONS_NAME,
  PARENT_OWNER,
  PARENT_TABLE,
  PARENT_COLS,
  PARENT_CONS_NAME
)
as
 SELECT U1.NAME, T.NAME, DBE_DIAGNOSE.DBA_LISTCOLS(U1.NAME, '"'||T.NAME||'"', C.COL_LIST) CONS_COLS, C.CONS_NAME, U2.NAME, T3.NAME, 
     DBE_DIAGNOSE.DBA_LISTCOLS(U3.NAME, '"'||T3.NAME||'"', I.COL_LIST) REF_COLS, I.NAME
  FROM SYS.SYS_USERS U1, SYS.SYS_USERS U2, SYS.SYS_CONSTRAINT_DEFS C, SYS.SYS_TABLES T, SYS.SYS_INDEXES I, SYS.SYS_USERS U3, SYS.SYS_TABLES T3
  WHERE C.USER# = U1.ID AND T.USER# = U1.ID AND T.ID = C.TABLE# AND C.REF_USER# = I.USER# AND C.REF_USER# = U2.ID AND C.REF_TABLE# = I.TABLE# AND C.REF_CONS = I.ID AND T.RECYCLED = 0
    AND I.USER# = U3.ID AND T3.USER# = U3.ID AND I.TABLE# = T3.ID AND C.CONS_TYPE = 2 AND DBE_DIAGNOSE.TENANT_CHECK(0, U1.TENANT_ID)
/

CREATE OR REPLACE VIEW  MY_FOREIGN_DEPENDENCY 
(
  CHILD_OWNER,
  CHILD_TABLE,
  CHILD_COLS,
  CHILD_CONS_NAME,
  PARENT_OWNER,
  PARENT_TABLE,
  PARENT_COLS,
  PARENT_CONS_NAME
)
as 
 SELECT U1.NAME, T.NAME,DBE_DIAGNOSE.DBA_LISTCOLS(U1.NAME, '"'||T.NAME||'"', C.COL_LIST) CONS_COLS, C.CONS_NAME, U2.NAME, T3.NAME, 
     DBE_DIAGNOSE.DBA_LISTCOLS(U3.NAME, '"'||T3.NAME||'"', I.COL_LIST) REF_COLS, I.NAME
  FROM SYS.SYS_USERS U1, SYS.SYS_USERS U2, SYS.SYS_CONSTRAINT_DEFS C, SYS.SYS_TABLES T, SYS.SYS_INDEXES I, SYS.SYS_USERS U3, SYS.SYS_TABLES T3
  WHERE C.USER# = U1.ID AND T.USER# = U1.ID AND T.ID = C.TABLE# AND C.REF_USER# = I.USER# AND C.REF_USER# = U2.ID AND C.REF_TABLE# = I.TABLE# AND C.REF_CONS = I.ID AND T.RECYCLED = 0
    AND I.USER# = U3.ID AND T3.USER# = U3.ID AND I.TABLE# = T3.ID AND C.CONS_TYPE = 2 AND U1.NAME = user    
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_FOREIGN_DEPENDENCY      FOR SYS.ADM_FOREIGN_DEPENDENCY 
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_FOREIGN_DEPENDENCY      FOR SYS.MY_FOREIGN_DEPENDENCY 
/
GRANT SELECT ON MY_FOREIGN_DEPENDENCY TO PUBLIC
/ 
--43
GRANT EXECUTE ON SYS.DBE_OUTPUT TO PUBLIC
/
GRANT EXECUTE ON SYS.DBE_LOB TO PUBLIC
/
GRANT EXECUTE ON SYS.DBE_RANDOM TO PUBLIC
/
GRANT EXECUTE ON SYS.DBE_SQL TO PUBLIC
/
GRANT EXECUTE ON SYS.DBE_STD TO PUBLIC
/
GRANT EXECUTE ON SYS.DBE_STATS TO PUBLIC
/
GRANT EXECUTE ON SYS.DBE_UTIL TO PUBLIC
/
GRANT EXECUTE ON SYS.DBE_TASK TO DBA
/
GRANT EXECUTE ON SYS.DBE_DEBUG TO PUBLIC;
/
CREATE OR REPLACE PUBLIC SYNONYM  DV_RSRC_CONTROL_GROUP FOR SYS.DV_RSRC_CONTROL_GROUP
/
GRANT EXECUTE ON SYS.DBE_RSRC_MGR TO DBA
/
--44
CREATE OR REPLACE VIEW ADM_TENANTS
(
  TENANT_ID,
  NAME,
  DEFAULT_TABLESPACE,
  SPACE_NUM,
  CREATED_TIME
)
AS
  SELECT T.TENANT_ID, T.NAME, TS.NAME, T.SPACE_NUM, T.CTIME FROM SYS.SYS_TENANTS T JOIN SYS.DV_TABLESPACES TS ON DBE_DIAGNOSE.TENANT_CHECK(0, T.TENANT_ID) AND T.DATA_SPACE#=TS.ID
/
CREATE OR REPLACE PUBLIC SYNONYM ADM_TENANTS FOR SYS.ADM_TENANTS
/
CREATE OR REPLACE PUBLIC SYNONYM DV_TENANT_TABLESPACES FOR SYS.DV_TENANT_TABLESPACES
/
CREATE OR REPLACE PUBLIC SYNONYM DV_RSRC_MONITOR FOR SYS.DV_RSRC_MONITOR
/
--45
GRANT ALTER ANY INDEX, 
      ALTER ANY MATERIALIZED VIEW, 
      ALTER ANY PROCEDURE, 
      ALTER ANY ROLE, 
      ALTER ANY SEQUENCE,
      ALTER ANY TABLE, 
      ALTER ANY TRIGGER, 
      ALTER DATABASE, 
      ALTER PROFILE, 
      ALTER SESSION, 
      ALTER SYSTEM, 
      ALTER TABLESPACE, 
      ALTER USER, 
      CREATE ANY INDEX, 
      CREATE ANY MATERIALIZED VIEW, 
      CREATE ANY PROCEDURE, 
      CREATE ANY SEQUENCE, 
      CREATE ANY SYNONYM, 
      CREATE ANY TABLE, 
      CREATE ANY TRIGGER, 
      CREATE ANY VIEW, 
      CREATE DATABASE, 
      CREATE MATERIALIZED VIEW, 
      CREATE NODE, 
      CREATE PROCEDURE, 
      CREATE PROFILE, 
      CREATE PUBLIC SYNONYM, 
      CREATE ROLE, 
      CREATE SEQUENCE, 
      CREATE SESSION, 
      CREATE SYNONYM, 
      CREATE TABLE, 
      CREATE TABLESPACE, 
      CREATE TRIGGER, 
      CREATE USER, 
      CREATE VIEW, 
      DROP ANY INDEX, 
      DROP ANY MATERIALIZED VIEW, 
      DROP ANY PROCEDURE, 
      DROP ANY ROLE, 
      DROP ANY SEQUENCE, 
      DROP ANY SYNONYM, 
      DROP ANY TABLE, 
      DROP ANY TRIGGER, 
      DROP ANY VIEW, 
      DROP PROFILE, 
      DROP PUBLIC SYNONYM, 
      DROP TABLESPACE, 
      DROP USER, 
      FLASHBACK ANY TABLE, 
      FLASHBACK ARCHIVE ADMINISTER, 
      GLOBAL QUERY REWRITE, 
      GRANT ANY OBJECT PRIVILEGE, 
      GRANT ANY PRIVILEGE, 
      GRANT ANY ROLE, 
      LOCK ANY TABLE, 
      MANAGE TABLESPACE, 
      ON COMMIT REFRESH, 
      PURGE DBA_RECYCLEBIN, 
      READ ANY TABLE, 
      SELECT ANY SEQUENCE, 
      SELECT ANY TABLE, 
      UNLIMITED TABLESPACE, 
      UNDER ANY VIEW, 
      COMMENT ANY TABLE, 
      UPDATE ANY TABLE, 
      INSERT ANY TABLE, 
      DELETE ANY TABLE, 
      EXECUTE ANY PROCEDURE, 
      SYSBACKUP, 
      SYSDBA, 
      SYSOPER, 
      ANALYZE ANY, 
      DROP NODE, 
      ALTER NODE, 
      CREATE ANY DIRECTORY, 
      DROP ANY DIRECTORY, 
      CREATE ANY SQL MAP, 
      DROP ANY SQL MAP, 
      CREATE ANY TYPE, 
      CREATE TYPE, 
      DROP ANY TYPE, 
      EXECUTE ANY TYPE, 
      CREATE CTRLFILE, 
      CREATE LIBRARY, 
      EXEMPT REDACTION POLICY, 
      CREATE ANY LIBRARY, 
      DROP ANY LIBRARY, 
      EXECUTE ANY LIBRARY, 
      EXEMPT ACCESS POLICY, 
      SELECT ANY DICTIONARY,
      CREATE TENANT,
      ALTER TENANT,
      FORCE ANY TRANSACTION,
      DROP TENANT,
      CREATE DATABASE LINK,
      ALTER DATABASE LINK,
      DROP DATABASE LINK,
      USE ANY TABLESPACE TO DBA WITH ADMIN OPTION
/

--46
DROP PUBLIC SYNONYM IF EXISTS 			USER_REDACTION_POLICIES
/
DROP PUBLIC SYNONYM IF EXISTS 			DBA_REDACTION_POLICIES
/
DROP PUBLIC SYNONYM IF EXISTS 			DBA_POLICIES
/
DROP PUBLIC SYNONYM IF EXISTS 			USER_POLICIES
/
DROP SYNONYM IF EXISTS 					SYS.DIRECTORY$
/
DROP PUBLIC SYNONYM IF EXISTS 			V$RSRC_CONSUMER_GROUP
/
DROP PUBLIC SYNONYM IF EXISTS 			DBA_RSRC_PLAN_DIRECTIVES
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_RSRC_GROUP_MAPPINGS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_RSRC_CONSUMER_GROUPS
/
DROP PUBLIC SYNONYM IF EXISTS 			DBA_RSRC_PLANS
/
DROP PUBLIC SYNONYM IF EXISTS 			ALL_CONS_COLUMNS
/
DROP SYNONYM IF EXISTS 					SYS.AUD$
/
DROP SYNONYM IF EXISTS 					SYS.VIEWCOL$
/
DROP SYNONYM IF EXISTS					SYS.VIEW$
/
DROP SYNONYM IF EXISTS					SYS.USER_ROLES$
/
DROP SYNONYM IF EXISTS					SYS.USER_HISTORY$
/
DROP SYNONYM IF EXISTS					SYS.USER$
/
DROP SYNONYM IF EXISTS					SYS.TMP_SEG_STAT$
/		
DROP SYNONYM IF EXISTS					SYS.TABLEPART$
/
DROP SYNONYM IF EXISTS					SYS.TABLE$
/
DROP SYNONYM IF EXISTS					SYS.SYS_PRIVS$
/
DROP SYNONYM IF EXISTS					SYS.SYNONYM$
/
DROP SYNONYM IF EXISTS					SYS.SHADOW_INDEXPART$
/
DROP SYNONYM IF EXISTS					SYS.SHADOW_INDEX$
/
DROP SYNONYM IF EXISTS					SYS.SEQUENCE$
/
DROP SYNONYM IF EXISTS					SYS.ROLES$
/
DROP SYNONYM IF EXISTS					SYS.RECYCLEBIN$
/
DROP SYNONYM IF EXISTS					SYS.PROFILE$
/
DROP SYNONYM IF EXISTS					SYS.PROC_ARGS$
/
DROP SYNONYM IF EXISTS					SYS.PROC$
/
DROP SYNONYM IF EXISTS					SYS.PENDING_TRANS$
/
DROP SYNONYM IF EXISTS					SYS.PARTSTORE$
/
DROP SYNONYM IF EXISTS					SYS.PARTOBJECT$
/
DROP SYNONYM IF EXISTS					SYS.PARTCOLUMN$
/
DROP SYNONYM IF EXISTS					SYS.OBJECT_PRIVS$
/
DROP SYNONYM IF EXISTS					SYS.MON_MODS_ALL$
/
DROP SYNONYM IF EXISTS					SYS.LOGIC_REP$
/
DROP SYNONYM IF EXISTS					SYS.LOBPART$
/
DROP SYNONYM IF EXISTS					SYS.LOB$
/
DROP SYNONYM IF EXISTS					SYS.LINK$
/
DROP SYNONYM IF EXISTS					SYS.JOB$
/
DROP SYNONYM IF EXISTS					SYS.INDEXPART$
/
DROP SYNONYM IF EXISTS					SYS.INDEX$
/
DROP SYNONYM IF EXISTS					SYS.HISTGRAM$
/
DROP SYNONYM IF EXISTS					SYS.HIST_HEAD$
/
DROP SYNONYM IF EXISTS					SYS.GARBAGE_SEGMENT$
/
DROP SYNONYM IF EXISTS					SYS.EXTERNAL$
/
DROP SYNONYM IF EXISTS					SYS.DUAL
/
DROP SYNONYM IF EXISTS					SYS.DEPENDENCY$
/
DROP SYNONYM IF EXISTS					SYS.DBA_EXP$TBL_RELATIONS
/
DROP SYNONYM IF EXISTS					SYS.DBA_EXP$TBL_ORDER
/
DROP SYNONYM IF EXISTS					SYS.DATA_NODES$
/
DROP SYNONYM IF EXISTS					SYS.CONSDEF$
/
DROP SYNONYM IF EXISTS					SYS.COMMENT$
/
DROP SYNONYM IF EXISTS					SYS.COLUMN$
/
DROP SYNONYM IF EXISTS					SYS.BACKUP_SET$
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_LONGSQL
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_DBASEGMENTS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_SEGMENT
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_LIBRARYCACHE
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_LATCH
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_WAITSTAT
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_PARAMETER
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_SQLAREA
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_SYSTEM_EVENT
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_SYSTEM
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_SYSSTAT
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_SNAPSHOT
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HIST_WR_CONTROL
/
DROP PUBLIC SYNONYM IF EXISTS			WRH$_PARAMETER
/
DROP PUBLIC SYNONYM IF EXISTS			WRH$_SQLAREA
/
DROP PUBLIC SYNONYM IF EXISTS			WRH$_SYSSTAT
/
DROP PUBLIC SYNONYM IF EXISTS			WRH$_SYSTEM
/
DROP PUBLIC SYNONYM IF EXISTS			WRH$_SYSTEM_EVENT
/
DROP PUBLIC SYNONYM IF EXISTS			WRM$_SNAPSHOT
/
DROP PUBLIC SYNONYM IF EXISTS			WRM$_WR_CONTROL
/
DROP PUBLIC SYNONYM IF EXISTS			WSR$_DBA_SEGMENTS
/
DROP PUBLIC SYNONYM IF EXISTS			WSR$_LATCH
/
DROP PUBLIC SYNONYM IF EXISTS			WSR$_LIBRARYCACHE
/
DROP PUBLIC SYNONYM IF EXISTS			WSR$_LONGSQL
/
DROP PUBLIC SYNONYM IF EXISTS			WSR$_SEGMENT
/
DROP PUBLIC SYNONYM IF EXISTS			WSR$_WAITSTAT
/
DROP PUBLIC SYNONYM IF EXISTS			WSR$SQL_LIST
/
DROP PUBLIC SYNONYM IF EXISTS			WSR$SQL_LIST_PLAN
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_VIEW_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_TAB_COLS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_SOURCE
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_SEQUENCES
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_PROCEDURES
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_JOBS_RUNNING
/
DROP PUBLIC SYNONYM IF EXISTS			USER_JOBS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_JOBS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_JOBS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_PROCEDURES
/
DROP PUBLIC SYNONYM IF EXISTS			USER_DEPENDENCIES
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_DEPENDENCIES
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_DEPENDENCIES
/
DROP PUBLIC SYNONYM IF EXISTS			USER_FREE_SPACE
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_FREE_SPACE
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_ARGUMENTS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_ARGUMENTS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_ARGUMENTS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_USERS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_DATA_FILES
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_ROLES
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_OBJECTS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_BACKUP_SET
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_TRIGGERS
/			
DROP PUBLIC SYNONYM IF EXISTS			USER_CONS_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_TRIGGERS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_TRIGGERS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_PROCEDURES
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_PROCEDURES
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_SOURCE
/
DROP PUBLIC SYNONYM IF EXISTS			USER_SOURCE
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_SOURCE
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_CONSTRAINTS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_CONSTRAINTS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_CONSTRAINTS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_USERS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_IND_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_IND_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_IND_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_TAB_PARTITIONS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_TAB_PARTITIONS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_TAB_PARTITIONS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_SEQUENCES
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_SEQUENCES
/
DROP PUBLIC SYNONYM IF EXISTS			USER_TAB_PRIVS
/			
DROP PUBLIC SYNONYM IF EXISTS			DBA_TAB_PRIVS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_ROLE_PRIVS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_ROLE_PRIVS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_SYS_PRIVS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_SYS_PRIVS
/			
DROP PUBLIC SYNONYM IF EXISTS			ALL_USER_SYS_PRIVS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_PROFILES
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_USERS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_COL_COMMENTS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_COL_COMMENTS
/			
DROP PUBLIC SYNONYM IF EXISTS			USER_COL_COMMENTS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_TAB_COMMENTS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_TAB_COMMENTS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_TAB_COMMENTS
/		
DROP PUBLIC SYNONYM IF EXISTS			ALL_SYNONYMS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_SYNONYMS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_SYNONYMS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_TABLESPACES
/
DROP PUBLIC SYNONYM IF EXISTS			USER_OBJECTS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_OBJECTS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_INDEXES
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_INDEXES
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_INDEXES
/
DROP PUBLIC SYNONYM IF EXISTS			USER_VIEW_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_VIEW_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_VIEWS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_VIEWS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_VIEWS
/			
DROP PUBLIC SYNONYM IF EXISTS			DBA_TAB_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_TAB_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_DBLINK_TAB_COLUMNS
/			
DROP PUBLIC SYNONYM IF EXISTS			DBA_DBLINK_TAB_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_TAB_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_TAB_COLS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_PART_KEY_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_PART_KEY_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_PART_KEY_COLUMNS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_PART_STORE
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_PART_STORE
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_PART_STORE
/
DROP PUBLIC SYNONYM IF EXISTS			USER_PART_TABLES
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_PART_TABLES
/			
DROP PUBLIC SYNONYM IF EXISTS			DBA_PART_TABLES
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_DIST_RULE_COLS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_TAB_COLS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_TABLES
/			
DROP PUBLIC SYNONYM IF EXISTS			DBA_DBLINK_TABLES
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_DBLINK_TABLES
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_TABLES
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_TABLES
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_SEGMENTS	
/
DROP PUBLIC SYNONYM IF EXISTS			USER_SEGMENTS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_DIRECTORIES
/
DROP VIEW IF EXISTS				SYS.ALL_DIRECTORIES
/			
DROP VIEW IF EXISTS				SYS.USER_DEPENDENCIES
/			
DROP VIEW IF EXISTS				SYS.DBA_DEPENDENCIES
/
DROP VIEW IF EXISTS				SYS.ALL_DEPENDENCIES
/
DROP PUBLIC SYNONYM IF EXISTS			USER_HISTOGRAMS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_HISTOGRAMS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_HISTOGRAMS
/
DROP VIEW IF EXISTS				SYS.DBA_JOBS_RUNNING
/			
DROP VIEW IF EXISTS				SYS.USER_JOBS
/
DROP VIEW IF EXISTS				SYS.DBA_JOBS
/			
DROP VIEW IF EXISTS				SYS.ALL_JOBS
/
DROP VIEW IF EXISTS				ALL_DB_LINKS
/			
DROP VIEW IF EXISTS				USER_HISTOGRAMS
/
DROP VIEW IF EXISTS				DBA_HISTOGRAMS
/			
DROP VIEW IF EXISTS				ALL_HISTOGRAMS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_PART_COL_STATISTICS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_PART_COL_STATISTICS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_PART_COL_STATISTICS
/
DROP VIEW IF EXISTS				USER_PART_COL_STATISTICS
/			
DROP VIEW IF EXISTS				DBA_PART_COL_STATISTICS
/
DROP VIEW IF EXISTS				ALL_PART_COL_STATISTICS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_TAB_COL_STATISTICS
/	
DROP PUBLIC SYNONYM IF EXISTS			DBA_TAB_COL_STATISTICS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_TAB_COL_STATISTICS
/		
DROP VIEW IF EXISTS				USER_TAB_COL_STATISTICS
/
DROP VIEW IF EXISTS				DBA_TAB_COL_STATISTICS
/			
DROP VIEW IF EXISTS				ALL_TAB_COL_STATISTICS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_IND_STATISTICS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_IND_STATISTICS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_IND_STATISTICS
/
DROP VIEW IF EXISTS				USER_IND_STATISTICS
/			
DROP VIEW IF EXISTS				DBA_IND_STATISTICS
/
DROP VIEW IF EXISTS				ALL_IND_STATISTICS
/		
DROP PUBLIC SYNONYM IF EXISTS			USER_IND_PARTITIONS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_IND_PARTITIONS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_IND_PARTITIONS
/
DROP VIEW IF EXISTS				USER_IND_PARTITIONS
/
DROP VIEW IF EXISTS				DBA_IND_PARTITIONS
/			
DROP VIEW IF EXISTS				ALL_IND_PARTITIONS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_TAB_STATISTICS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_TAB_STATISTICS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_TAB_STATISTICS
/
DROP VIEW IF EXISTS				USER_TAB_STATISTICS
/			
DROP VIEW IF EXISTS				DBA_TAB_STATISTICS
/
DROP VIEW IF EXISTS				ALL_TAB_STATISTICS
/			
DROP VIEW IF EXISTS				USER_ARGUMENTS
/
DROP VIEW IF EXISTS				ALL_ARGUMENTS
/			
DROP VIEW IF EXISTS				DBA_ARGUMENTS
/
DROP VIEW IF EXISTS				DBA_ROLES
/
DROP VIEW IF EXISTS				USER_TRIGGERS
/			
DROP VIEW IF EXISTS				DBA_TRIGGERS
/
DROP VIEW IF EXISTS				ALL_TRIGGERS
/			
DROP VIEW IF EXISTS				ALL_CONS_COLUMNS
/
DROP VIEW IF EXISTS				USER_CONS_COLUMNS
/			
DROP VIEW IF EXISTS				USER_CONSTRAINTS
/
DROP VIEW IF EXISTS				ALL_CONSTRAINTS
/
DROP VIEW IF EXISTS				DBA_CONSTRAINTS
/			
DROP VIEW IF EXISTS				SYS.USER_USERS
/
DROP VIEW IF EXISTS				SYS.DBA_USERS
/			
DROP VIEW IF EXISTS				ALL_PROCEDURES
/
DROP VIEW IF EXISTS				DBA_PROCEDURES
/
DROP VIEW IF EXISTS				USER_PROCEDURES
/			
DROP VIEW IF EXISTS				ALL_TAB_PARTITIONS
/
DROP VIEW IF EXISTS				DBA_TAB_PARTITIONS
/			
DROP VIEW IF EXISTS				USER_TAB_PARTITIONS
/
DROP PUBLIC SYNONYM IF EXISTS			DBA_TAB_MODIFICATIONS
/
DROP PUBLIC SYNONYM IF EXISTS			USER_TAB_MODIFICATIONS
/
DROP PUBLIC SYNONYM IF EXISTS			ALL_TAB_MODIFICATIONS
/
DROP VIEW IF EXISTS				SYS.USER_TAB_MODIFICATIONS
/
DROP VIEW IF EXISTS				SYS.ALL_TAB_MODIFICATIONS
/			
DROP VIEW IF EXISTS				SYS.DBA_TAB_MODIFICATIONS 
/
DROP VIEW IF EXISTS				SYS.DBA_DATA_FILES
/			
DROP VIEW IF EXISTS				SYS.USER_IND_COLUMNS
/
DROP VIEW IF EXISTS				SYS.DBA_IND_COLUMNS
/
DROP VIEW IF EXISTS				SYS.ALL_IND_COLUMNS
/			
DROP VIEW IF EXISTS				USER_SEQUENCES
/
DROP VIEW IF EXISTS				ALL_SEQUENCES
/			
DROP VIEW IF EXISTS				DBA_SEQUENCES
/
DROP VIEW IF EXISTS				SYS.USER_TAB_PRIVS
/
DROP VIEW IF EXISTS				SYS.DBA_TAB_PRIVS
/			
DROP VIEW IF EXISTS				SYS.USER_ROLE_PRIVS
/
DROP VIEW IF EXISTS				SYS.DBA_ROLE_PRIVS
/			
DROP VIEW IF EXISTS				SYS.USER_SYS_PRIVS
/
DROP VIEW IF EXISTS				SYS.DBA_SYS_PRIVS
/
DROP VIEW IF EXISTS				SYS.ALL_USER_SYS_PRIVS
/			
DROP VIEW IF EXISTS				DBA_PROFILES
/
DROP VIEW IF EXISTS				ALL_SOURCE
/			
DROP VIEW IF EXISTS				DBA_SOURCE
/
DROP VIEW IF EXISTS				USER_SOURCE
/
DROP VIEW IF EXISTS				ALL_USERS
/			
DROP VIEW IF EXISTS				ALL_COL_COMMENTS
/
DROP VIEW IF EXISTS				DBA_COL_COMMENTS
/			
DROP VIEW IF EXISTS				USER_COL_COMMENTS
/
DROP VIEW IF EXISTS				ALL_TAB_COMMENTS
/
DROP VIEW IF EXISTS				DBA_TAB_COMMENTS
/			
DROP VIEW IF EXISTS				USER_TAB_COMMENTS
/
DROP VIEW IF EXISTS				SYS.ALL_SYNONYMS 
/			
DROP VIEW IF EXISTS				SYS.DBA_SYNONYMS
/
DROP VIEW IF EXISTS				USER_SYNONYMS
/
DROP VIEW IF EXISTS				USER_FREE_SPACE
/			
DROP VIEW IF EXISTS				DBA_FREE_SPACE
/
DROP VIEW IF EXISTS				DBA_TABLESPACES
/			
DROP VIEW IF EXISTS				USER_OBJECTS
/
DROP VIEW IF EXISTS				DBA_OBJECTS
/
DROP VIEW IF EXISTS				ALL_OBJECTS
/			
DROP VIEW IF EXISTS				USER_INDEXES
/
DROP VIEW IF EXISTS				DBA_INDEXES
/			
DROP VIEW IF EXISTS				ALL_INDEXES
/
DROP VIEW IF EXISTS				USER_VIEW_COLUMNS
/
DROP VIEW IF EXISTS				DBA_VIEW_COLUMNS
/			
DROP VIEW IF EXISTS				ALL_VIEW_COLUMNS
/
DROP VIEW IF EXISTS				USER_VIEWS
/			
DROP VIEW IF EXISTS				DBA_VIEWS
/
DROP VIEW IF EXISTS				ALL_VIEWS
/
DROP VIEW IF EXISTS				ALL_DBLINK_TAB_COLUMNS
/			
DROP VIEW IF EXISTS				DBA_DBLINK_TAB_COLUMNS
/
DROP VIEW IF EXISTS				DBA_TAB_COLUMNS
/			
DROP VIEW IF EXISTS				ALL_TAB_COLUMNS
/
DROP VIEW IF EXISTS				USER_TAB_COLUMNS
/
DROP VIEW IF EXISTS				USER_TAB_COLS
/			
DROP VIEW IF EXISTS				USER_PART_KEY_COLUMNS
/
DROP VIEW IF EXISTS				DBA_PART_KEY_COLUMNS
/			
DROP VIEW IF EXISTS				ALL_PART_KEY_COLUMNS
/
DROP VIEW IF EXISTS				DBA_PART_TABLES
/
DROP VIEW IF EXISTS				ALL_PART_TABLES
/			
DROP VIEW IF EXISTS				USER_PART_TABLES
/
DROP VIEW IF EXISTS				DBA_PART_STORE
/			
DROP VIEW IF EXISTS				ALL_PART_STORE
/
DROP VIEW IF EXISTS				USER_PART_STORE
/			
DROP VIEW IF EXISTS				ALL_DIST_RULE_COLS
/
DROP VIEW IF EXISTS				DBA_TAB_COLS
/			
DROP VIEW IF EXISTS				ALL_TAB_COLS
/
DROP VIEW IF EXISTS				USER_TABLES
/			
DROP VIEW IF EXISTS				DBA_DBLINK_TABLES
/
DROP VIEW IF EXISTS				USER_POLICIES
/			
DROP VIEW IF EXISTS				DBA_POLICIES
/
DROP VIEW IF EXISTS				USER_REDACTION_POLICIES
/			
DROP VIEW IF EXISTS				DBA_REDACTION_POLICIES
/
DROP VIEW IF EXISTS				ALL_DBLINK_TABLES
/			
DROP VIEW IF EXISTS				ALL_TABLES
/
DROP VIEW IF EXISTS				DBA_TABLES
/			
DROP VIEW IF EXISTS				DBA_SEGMENTS
/
DROP VIEW IF EXISTS				USER_SEGMENTS
/			
DROP VIEW IF EXISTS				DBA_BACKUP_SET
/
DROP SYNONYM IF EXISTS					DUAL
/
DROP PUBLIC SYNONYM IF EXISTS			DUAL
/
DROP PUBLIC SYNONYM IF EXISTS			V$SESSION_EX
/
DROP PUBLIC SYNONYM IF EXISTS			V$GTS_STATUS
/
DROP PUBLIC SYNONYM IF EXISTS			V$XACT_LOCK
/
DROP PUBLIC SYNONYM IF EXISTS			V$BUFFER_POOL_STATISTICS
/
DROP PUBLIC SYNONYM IF EXISTS			V$VM_FUNC_STACK
/
DROP PUBLIC SYNONYM IF EXISTS			V$LATCH
/
DROP PUBLIC SYNONYM IF EXISTS			V$WAITSTAT
/
DROP PUBLIC SYNONYM IF EXISTS			V$SEGMENT_STATISTICS
/
DROP PUBLIC SYNONYM IF EXISTS			V$REACTOR_POOL
/
DROP PUBLIC SYNONYM IF EXISTS			V$CONTROLFILE
/
DROP PUBLIC SYNONYM IF EXISTS			V$USER_ADVISORY_LOCKS
/
DROP PUBLIC SYNONYM IF EXISTS			V$BACKUP_PROCESS
/
DROP PUBLIC SYNONYM IF EXISTS			V$DYNAMIC_VIEW_COLUMN
/
DROP PUBLIC SYNONYM IF EXISTS			V$DYNAMIC_VIEW
/
DROP PUBLIC SYNONYM IF EXISTS			V$USER_ASTATUS_MAP
/
DROP PUBLIC SYNONYM IF EXISTS			V$RESOURCE_MAP
/
DROP PUBLIC SYNONYM IF EXISTS			V$GLOBAL_TRANSACTIONS
/
DROP PUBLIC SYNONYM IF EXISTS			V$ALL_TRANSACTION
/
DROP PUBLIC SYNONYM IF EXISTS			V$TRANSACTION
/
DROP PUBLIC SYNONYM IF EXISTS			V$VERSION
/
DROP PUBLIC SYNONYM IF EXISTS			V$SYSTEM
/
DROP PUBLIC SYNONYM IF EXISTS			V$SYSSTAT
/
DROP PUBLIC SYNONYM IF EXISTS			V$DATAFILE
/
DROP PUBLIC SYNONYM IF EXISTS			V$ME
/
DROP PUBLIC SYNONYM IF EXISTS			V$SYSTEM_EVENT
/
DROP PUBLIC SYNONYM IF EXISTS			V$SESSION_EVENT
/
DROP PUBLIC SYNONYM IF EXISTS			V$SESSION_WAIT
/
DROP PUBLIC SYNONYM IF EXISTS			V$SQLAREA
/
DROP PUBLIC SYNONYM IF EXISTS			V$SPINLOCK
/
DROP PUBLIC SYNONYM IF EXISTS			V$TABLESPACE
/
DROP PUBLIC SYNONYM IF EXISTS			V$MANAGED_STANDBY
/
DROP PUBLIC SYNONYM IF EXISTS			V$LOCKED_OBJECT
/
DROP PUBLIC SYNONYM IF EXISTS			V$SGA
/
DROP PUBLIC SYNONYM IF EXISTS			V$DATABASE
/
DROP PUBLIC SYNONYM IF EXISTS			V$ARCHIVE_DEST_STATUS
/
DROP PUBLIC SYNONYM IF EXISTS			V$ARCHIVE_PROCESSES
/
DROP PUBLIC SYNONYM IF EXISTS			V$ARCHIVE_GAP
/
DROP PUBLIC SYNONYM IF EXISTS			V$ARCHIVED_LOG
/
DROP PUBLIC SYNONYM IF EXISTS			V$LOCK
/
DROP PUBLIC SYNONYM IF EXISTS			V$DB_OBJECT_CACHE
/
DROP PUBLIC SYNONYM IF EXISTS			V$TEMP_POOL
/
DROP PUBLIC SYNONYM IF EXISTS			V$USER_PARAMETER
/
DROP PUBLIC SYNONYM IF EXISTS			V$PARAMETER
/
DROP PUBLIC SYNONYM IF EXISTS			V$BUFFER_POOL
/
DROP PUBLIC SYNONYM IF EXISTS			V$SESSION
/
DROP PUBLIC SYNONYM IF EXISTS			V$LOGFILE
/
DROP PUBLIC SYNONYM IF EXISTS			V$JOBS_RUNNING
/
DROP PUBLIC SYNONYM IF EXISTS			V$INSTANCE
/
DROP PUBLIC SYNONYM IF EXISTS			V$HBA
/
DROP PUBLIC SYNONYM IF EXISTS			V$HA_SYNC_INFO
/
DROP PUBLIC SYNONYM IF EXISTS			V$FREE_SPACE
/
DROP PUBLIC SYNONYM IF EXISTS			V$PL_MANAGER
/
DROP PUBLIC SYNONYM IF EXISTS			V$DC_POOL
/
DROP PUBLIC SYNONYM IF EXISTS			V$OPEN_CURSOR
/
DROP PUBLIC SYNONYM IF EXISTS			V$TEMP_UNDO_SEGMENT
/
DROP PUBLIC SYNONYM IF EXISTS			V$UNDO_SEGMENT
/
DROP PUBLIC SYNONYM IF EXISTS			V$LIBRARYCACHE
/
DROP PUBLIC SYNONYM IF EXISTS			V$SQLPOOL
/
DROP PUBLIC SYNONYM IF EXISTS			V$SGASTAT
/
DROP PUBLIC SYNONYM IF EXISTS			V$REPL_STATUS
/
DROP PUBLIC SYNONYM IF EXISTS			V$PL_REFSQLS
/
DROP VIEW IF EXISTS				SYS.V$GTS_STATUS
/			
DROP VIEW IF EXISTS				SYS.V$XACT_LOCK
/
DROP VIEW IF EXISTS				SYS.V$VM_FUNC_STACK
/			
DROP VIEW IF EXISTS				SYS.V$WAITSTAT
/
DROP VIEW IF EXISTS				SYS.V$USER_ADVISORY_LOCKS
/			
DROP VIEW IF EXISTS				SYS.V$SQLAREA
/
DROP VIEW IF EXISTS				SYS.V$SPINLOCK
/			
DROP VIEW IF EXISTS				SYS.V$SGA
/
DROP VIEW IF EXISTS				SYS.V$SESSION_WAIT
/			
DROP VIEW IF EXISTS				SYS.V$SESSION_EVENT
/
DROP VIEW IF EXISTS				SYS.V$USER_PARAMETER
/			
DROP VIEW IF EXISTS				SYS.V$BUFFER_POOL
/
DROP VIEW IF EXISTS				SYS.V$BACKUP_PROCESS
/			
DROP VIEW IF EXISTS				SYS.V$ARCHIVE_PROCESSES
/
DROP VIEW IF EXISTS				SYS.V$ARCHIVE_GAP
/			
DROP VIEW IF EXISTS				SYS.V$ARCHIVE_DEST_STATUS
/
DROP VIEW IF EXISTS				SYS.V$ARCHIVED_LOG
/
DROP VIEW IF EXISTS				SYS.V$GLOBAL_TRANSACTIONS
/			
DROP VIEW IF EXISTS				SYS.V$ALL_TRANSACTION
/
DROP VIEW IF EXISTS				SYS.V$DYNAMIC_VIEW_COLUMN
/			
DROP VIEW IF EXISTS				SYS.V$DYNAMIC_VIEW
/
DROP VIEW IF EXISTS				SYS.V$DC_POOL
/			
DROP VIEW IF EXISTS				SYS.V$DB_OBJECT_CACHE
/
DROP VIEW IF EXISTS				SYS.V$DATAFILE
/
DROP VIEW IF EXISTS				SYS.V$DATABASE
/			
DROP VIEW IF EXISTS				SYS.V$CONTROLFILE
/
DROP VIEW IF EXISTS				SYS.V$BUFFER_POOL_STATISTICS
/			
DROP VIEW IF EXISTS				SYS.V$LOCK
/
DROP VIEW IF EXISTS				SYS.V$LATCH
/			
DROP VIEW IF EXISTS				SYS.V$JOBS_RUNNING
/
DROP VIEW IF EXISTS				SYS.V$INSTANCE
/
DROP VIEW IF EXISTS				SYS.V$HBA
/
DROP VIEW IF EXISTS				SYS.V$HA_SYNC_INFO
/			
DROP VIEW IF EXISTS				SYS.V$FREE_SPACE
/
DROP VIEW IF EXISTS				SYS.V$PARAMETER
/			
DROP VIEW IF EXISTS				SYS.V$OPEN_CURSOR
/
DROP VIEW IF EXISTS				SYS.V$ME
/			
DROP VIEW IF EXISTS				SYS.V$MANAGED_STANDBY
/
DROP VIEW IF EXISTS				SYS.V$LONGSQL
/
DROP VIEW IF EXISTS				SYS.V$LOGFILE
/
DROP VIEW IF EXISTS				SYS.V$LOCKED_OBJECT
/			
DROP VIEW IF EXISTS				SYS.V$SESSION_EX
/
DROP VIEW IF EXISTS				SYS.V$SESSION
/			
DROP VIEW IF EXISTS				SYS.V$SEGMENT_STATISTICS
/
DROP VIEW IF EXISTS				SYS.V$RESOURCE_MAP
/			
DROP VIEW IF EXISTS				SYS.V$REACTOR_POOL
/
DROP VIEW IF EXISTS				SYS.V$TEMP_UNDO_SEGMENT
/
DROP VIEW IF EXISTS				SYS.V$USER_ASTATUS_MAP
/
DROP VIEW IF EXISTS				SYS.V$VERSION
/			
DROP VIEW IF EXISTS				SYS.V$UNDO_SEGMENT
/
DROP VIEW IF EXISTS				SYS.V$TRANSACTION
/			
DROP VIEW IF EXISTS				SYS.V$TEMP_POOL
/
DROP VIEW IF EXISTS				SYS.V$TABLESPACE
/			
DROP VIEW IF EXISTS				SYS.V$SYSTEM_EVENT
/
DROP VIEW IF EXISTS				SYS.V$SYSTEM
/
DROP VIEW IF EXISTS				SYS.V$SYSSTAT
/
DROP VIEW IF EXISTS				SYS.V$LIBRARYCACHE
/
DROP VIEW IF EXISTS				SYS.V$SQLPOOL
/
DROP VIEW IF EXISTS				SYS.V$SGASTAT
/
DROP VIEW IF EXISTS				SYS.V$REPL_STATUS
/
DROP VIEW IF EXISTS				SYS.V$PL_REFSQLS
/
DROP VIEW IF EXISTS				SYS.V$PL_MANAGER
/

--47
CREATE OR REPLACE VIEW MY_NOLOG_OBJECTS
(
  USER_NAME,
  TABLE_NAME, 
  PARTITION_NAME,
  SUBPARTITION_NAME  
)
AS
  SELECT ME.USER_NAME, T.NAME, '', '' FROM SYS.DV_ME ME, SYS.SYS_TABLES T WHERE (T.FLAG & 4) AND T.USER# = ME.USER_ID
  UNION ALL
  SELECT ME.USER_NAME, T.NAME, TP.NAME, '' FROM SYS.DV_ME ME, SYS.SYS_TABLES T, SYS.SYS_TABLE_PARTS TP WHERE (TP.FLAGS & 16) AND TP.TABLE# = T.ID AND TP.USER# = T.USER# AND TP.USER# = ME.USER_ID
  UNION ALL
  SELECT ME.USER_NAME, T.NAME, TP.NAME, TSUBP.NAME FROM SYS.DV_ME ME, SYS.SYS_TABLES T, SYS.SYS_TABLE_PARTS TP, SYS.SYS_SUB_TABLE_PARTS TSUBP
  WHERE (TSUBP.FLAGS & 16) AND TSUBP.USER# = TP.USER# AND TSUBP.TABLE# = TP.TABLE# AND TSUBP.PARENT_PART# = TP.PART# AND TSUBP.TABLE# = T.ID AND TSUBP.USER# = T.USER# AND TSUBP.USER# = ME.USER_ID
/
CREATE OR REPLACE PUBLIC SYNONYM  MY_NOLOG_OBJECTS      FOR SYS.MY_NOLOG_OBJECTS 
/
GRANT SELECT ON MY_NOLOG_OBJECTS TO PUBLIC
/

CREATE OR REPLACE VIEW ADM_NOLOG_OBJECTS
(
  USER_NAME,
  TABLE_NAME, 
  PARTITION_NAME,
  SUBPARTITION_NAME  
)
AS
  SELECT U.NAME, T.NAME, '', '' FROM SYS.SYS_USERS U, SYS.SYS_TABLES T WHERE (T.FLAG & 4) AND T.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, T.NAME, TP.NAME, '' FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_TABLE_PARTS TP WHERE (TP.FLAGS & 16) AND TP.TABLE# = T.ID AND TP.USER# = T.USER# AND TP.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
  UNION ALL
  SELECT U.NAME, T.NAME, TP.NAME, TSUBP.NAME FROM SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_TABLE_PARTS TP, SYS.SYS_SUB_TABLE_PARTS TSUBP
  WHERE (TSUBP.FLAGS & 16) AND TSUBP.USER# = TP.USER# AND TSUBP.TABLE# = TP.TABLE# AND TSUBP.PARENT_PART# = TP.PART# AND TSUBP.TABLE# = T.ID AND TSUBP.USER# = T.USER# AND TSUBP.USER# = U.ID AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/
CREATE OR REPLACE PUBLIC SYNONYM  ADM_NOLOG_OBJECTS      FOR SYS.ADM_NOLOG_OBJECTS 
/

CREATE OR REPLACE VIEW ADM_LOBS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  TABLESPACE_NAME
)
AS
  SELECT U.NAME, T.NAME, C.NAME, TS.NAME
  FROM SYS.SYS_LOBS L, SYS.SYS_USERS U, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.DV_TABLESPACES TS
  WHERE L.USER# = U.ID AND L.USER# = T.USER# AND L.TABLE# = T.ID AND
        L.USER# = C.USER# AND L.TABLE# = C.TABLE# AND L.COLUMN# = C.ID AND L.SPACE# = TS.ID
        AND DBE_DIAGNOSE.TENANT_CHECK(0, U.TENANT_ID)
/ 

CREATE OR REPLACE VIEW DB_LOBS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  TABLESPACE_NAME
)
AS
  SELECT ME.USER_NAME, T.NAME, C.NAME, TS.NAME
  FROM SYS.DV_ME ME, SYS.SYS_LOBS L, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.DV_TABLESPACES TS
  WHERE L.USER# = ME.USER_ID AND L.USER# = T.USER# AND L.TABLE# = T.ID AND
        L.USER# = C.USER# AND L.TABLE# = C.TABLE# AND L.COLUMN# = C.ID AND L.SPACE# = TS.ID
/ 

CREATE OR REPLACE VIEW MY_LOBS
(
  OWNER,
  TABLE_NAME,
  COLUMN_NAME,
  TABLESPACE_NAME
)
AS
  SELECT ME.USER_NAME, T.NAME, C.NAME, TS.NAME
  FROM SYS.DV_ME ME, SYS.SYS_LOBS L, SYS.SYS_TABLES T, SYS.SYS_COLUMNS C, SYS.DV_TABLESPACES TS
  WHERE L.USER# = ME.USER_ID AND L.USER# = T.USER# AND L.TABLE# = T.ID AND
        L.USER# = C.USER# AND L.TABLE# = C.TABLE# AND L.COLUMN# = C.ID AND L.SPACE# = TS.ID
/ 
CREATE OR REPLACE PUBLIC SYNONYM ADM_LOBS FOR SYS.ADM_LOBS
/
CREATE OR REPLACE PUBLIC SYNONYM DB_LOBS  FOR SYS.DB_LOBS
/
CREATE OR REPLACE PUBLIC SYNONYM MY_LOBS  FOR SYS.MY_LOBS
/
GRANT SELECT ON DB_LOBS TO PUBLIC
/
GRANT SELECT ON MY_LOBS TO PUBLIC
/

--48
CREATE OR REPLACE VIEW DV_UPGRADE_RECORD
(
TIME,
ACTION,
OLD_VERSION,
NEW_VERSION
)
AS SELECT * FROM SYS.SYS_UPGRADE_RECORD
/
CREATE OR REPLACE PUBLIC SYNONYM DV_UPGRADE_RECORD FOR SYS.DV_UPGRADE_RECORD
/
GRANT SELECT ON DV_UPGRADE_RECORD TO PUBLIC
/

--49
CREATE OR REPLACE VIEW ADM_PROMOTE_RECORD
(
TIME,
TYPE,
LOCAL_HOST,
PEER_HOST
)
AS SELECT * FROM SYS.SYS_PROMOTE_RECORD
/
CREATE OR REPLACE PUBLIC SYNONYM ADM_PROMOTE_RECORD FOR SYS.ADM_PROMOTE_RECORD
/

CREATE OR REPLACE PUBLIC SYNONYM  DV_USERS  FOR SYS.DV_USERS 
/

--50
CREATE OR REPLACE PUBLIC SYNONYM DV_DLSLOCKS    FOR SYS.DV_DLSLOCKS
/
CREATE OR REPLACE PUBLIC SYNONYM DV_DRC_INFO    FOR SYS.DV_DRC_INFO
/
CREATE OR REPLACE PUBLIC SYNONYM DV_DRC_BUF_INFO    FOR SYS.DV_DRC_BUF_INFO
/
CREATE OR REPLACE PUBLIC SYNONYM DV_DRC_RES_RATIO   FOR SYS.DV_DRC_RES_RATIO
/
CREATE OR REPLACE PUBLIC SYNONYM DV_DRC_GLOBAL_RES  FOR SYS.DV_DRC_GLOBAL_RES
/
CREATE OR REPLACE PUBLIC SYNONYM DV_DRC_RES_MAP     FOR SYS.DV_DRC_RES_MAP
/
CREATE OR REPLACE PUBLIC SYNONYM DV_BUF_CTRL_INFO   FOR SYS.DV_BUF_CTRL_INFO
/
CREATE OR REPLACE PUBLIC SYNONYM DV_DRC_LOCAL_LOCK_INFO   FOR SYS.DV_DRC_LOCAL_LOCK_INFO
/
CREATE OR REPLACE PUBLIC SYNONYM DV_DTC_CONVERTING_PAGE_CNT FOR SYS.DV_DTC_CONVERTING_PAGE_CNT
/
CREATE OR REPLACE PUBLIC SYNONYM DV_DTC_BUFFER_CTRL FOR SYS.DV_DTC_BUFFER_CTRL
/
CREATE OR REPLACE PUBLIC SYNONYM MES_STAT   FOR SYS.MES_STAT
/
CREATE OR REPLACE PUBLIC SYNONYM MES_ELAPSED    FOR SYS.MES_ELAPSED
/
CREATE OR REPLACE PUBLIC SYNONYM MES_QUEUE  FOR SYS.MES_QUEUE
/
CREATE OR REPLACE PUBLIC SYNONYM NODE_INFO  FOR SYS.NODE_INFO
/
CREATE OR REPLACE PUBLIC SYNONYM DV_REFORM_STATS    FOR SYS.DV_REFORM_STATS
/
CREATE OR REPLACE PUBLIC SYNONYM DV_SYNCPOINT_STATS    FOR SYS.DV_SYNCPOINT_STATS
/
